]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
* libltdl/lt__dirent.c [mingw] (opendir): Fix write of constant
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Sat, 18 Dec 2004 21:43:15 +0000 (21:43 +0000)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Sat, 18 Dec 2004 21:43:15 +0000 (21:43 +0000)
strings past end of buffer.
(opendir, readdir): Fix read past end of buffer.

ChangeLog
libltdl/lt__dirent.c

index 7e4d659e0720e3da7b472d1379bbd9404778e5fe..b5a608f4284e90f6e3b0751504a62a8346016d1e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-12-18  Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+       * libltdl/lt__dirent.c [mingw] (opendir): Fix write of constant
+       strings past end of buffer.
+       (opendir, readdir): Fix read past end of buffer.
+
 2004-12-17  Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
 
        * HACKING: Update list of non-Libtool-owned files.
index 6f0d68948d7e73d811240901a2899a2230f52aea..b3dd4fd35af9fdb20d0a8ef519ad7d1adab66df0 100644 (file)
@@ -46,24 +46,26 @@ closedir (DIR *entry)
 DIR *
 opendir (const char *path)
 {
-  char file_specification[LT_FILENAME_MAX];
+  char file_spec[LT_FILENAME_MAX];
   DIR *entry;
 
   assert (path != (char *) 0);
-  (void) strncpy (file_specification, path, LT_FILENAME_MAX-1);
-  (void) strcat (file_specification, "\\");
+  if (lt_strlcpy (file_spec, path, sizeof file_spec) >= sizeof file_spec
+      || lt_strlcat (file_spec, "\\", sizeof file_spec) >= sizeof file_spec)
+    return (DIR *) 0;
   entry = (DIR *) malloc (sizeof(DIR));
   if (entry != (DIR *) 0)
     {
       entry->firsttime = TRUE;
-      entry->hSearch = FindFirstFile (file_specification,
-                                     &entry->Win32FindData);
+      entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
 
       if (entry->hSearch == INVALID_HANDLE_VALUE)
        {
-         (void) strcat (file_specification, "\\*.*");
-         entry->hSearch = FindFirstFile (file_specification,
-                                         &entry->Win32FindData);
+         if (lt_strlcat (file_spec, "\\*.*", sizeof file_spec) < sizeof file_spec)
+           {
+             entry->hSearch = FindFirstFile (file_spec, &entry->Win32FindData);
+           }
+
          if (entry->hSearch == INVALID_HANDLE_VALUE)
            {
              entry = (free (entry), (DIR *) 0);
@@ -91,8 +93,9 @@ readdir (DIR *entry)
     }
 
   entry->firsttime = FALSE;
-  (void) strncpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
-                 LT_FILENAME_MAX - 1);
+  if (lt_strlcpy (entry->file_info.d_name, entry->Win32FindData.cFileName,
+       sizeof entry->file_info.d_name) >= sizeof entry->file_info.d_name)
+    return (struct dirent *) 0;
   entry->file_info.d_namlen = strlen (entry->file_info.d_name);
 
   return &entry->file_info;