From: Ralf Wildenhues Date: Sat, 18 Dec 2004 21:43:15 +0000 (+0000) Subject: * libltdl/lt__dirent.c [mingw] (opendir): Fix write of constant X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ddd48e1d2cd9853289b5908dcb862caf317b7c0;p=thirdparty%2Flibtool.git * libltdl/lt__dirent.c [mingw] (opendir): Fix write of constant strings past end of buffer. (opendir, readdir): Fix read past end of buffer. --- diff --git a/ChangeLog b/ChangeLog index 7e4d659e0..b5a608f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-12-18 Ralf Wildenhues + + * 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 * HACKING: Update list of non-Libtool-owned files. diff --git a/libltdl/lt__dirent.c b/libltdl/lt__dirent.c index 6f0d68948..b3dd4fd35 100644 --- a/libltdl/lt__dirent.c +++ b/libltdl/lt__dirent.c @@ -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;