use strncpy to avoid buffer-overruns
authorClaus Gittinger <cg@exept.de>
Mon, 12 Jan 1998 14:21:57 +0100
changeset 3164 4f37ae9c8961
parent 3163 212a539ee379
child 3165 b6bde90005a8
use strncpy to avoid buffer-overruns
DirStr.st
DirectoryStream.st
--- a/DirStr.st	Mon Jan 12 14:20:30 1998 +0100
+++ b/DirStr.st	Mon Jan 12 14:21:57 1998 +0100
@@ -596,15 +596,19 @@
     if (__INST(dirPointer) == nil) {
 	path = __INST(pathName);
 	if (__isString(path)) {
-	    strcpy(pattern, __stringVal(path));
-	    strcat(pattern, "\\*");
-	    d = FindFirstFile(pattern, &data);
-	    if (d == INVALID_HANDLE_VALUE) {
-		__INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
-	    } else {
-		__INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
-		entry = __MKSTRING( data.cFileName );
-		ok = true;
+	    int l = __stringSize(path);
+
+	    if (l < (sizeof(pattern)-4)) {
+	        strncpy(pattern, __stringVal(path), l);
+	        strcpy(pattern+l, "\\*");
+	        d = FindFirstFile(pattern, &data);
+	        if (d == INVALID_HANDLE_VALUE) {
+		    __INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
+	        } else {
+		    __INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
+		    entry = __MKSTRING( data.cFileName );
+		    ok = true;
+		}
 	    }
 	}
     }
@@ -673,5 +677,5 @@
 !DirectoryStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.41 1997-10-06 13:27:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Attic/DirStr.st,v 1.42 1998-01-12 13:21:57 cg Exp $'
 ! !
--- a/DirectoryStream.st	Mon Jan 12 14:20:30 1998 +0100
+++ b/DirectoryStream.st	Mon Jan 12 14:21:57 1998 +0100
@@ -596,15 +596,19 @@
     if (__INST(dirPointer) == nil) {
 	path = __INST(pathName);
 	if (__isString(path)) {
-	    strcpy(pattern, __stringVal(path));
-	    strcat(pattern, "\\*");
-	    d = FindFirstFile(pattern, &data);
-	    if (d == INVALID_HANDLE_VALUE) {
-		__INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
-	    } else {
-		__INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
-		entry = __MKSTRING( data.cFileName );
-		ok = true;
+	    int l = __stringSize(path);
+
+	    if (l < (sizeof(pattern)-4)) {
+	        strncpy(pattern, __stringVal(path), l);
+	        strcpy(pattern+l, "\\*");
+	        d = FindFirstFile(pattern, &data);
+	        if (d == INVALID_HANDLE_VALUE) {
+		    __INST(lastErrorNumber) = __MKSMALLINT(GetLastError());
+	        } else {
+		    __INST(dirPointer) = dp = __MKEXTERNALADDRESS(d); __STORE(self, dp);
+		    entry = __MKSTRING( data.cFileName );
+		    ok = true;
+		}
 	    }
 	}
     }
@@ -673,5 +677,5 @@
 !DirectoryStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.41 1997-10-06 13:27:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/DirectoryStream.st,v 1.42 1998-01-12 13:21:57 cg Exp $'
 ! !