Selaa lähdekoodia

Fix a possible overflow

We can easily create paths over MAX_PATH. (e.g. mkdir \\?\c:\foo\barrr..)
xtne6f 7 vuotta sitten
vanhempi
commit
001242865f
1 muutettua tiedostoa jossa 2 lisäystä ja 2 poistoa
  1. 2 2
      src/civetweb.c

+ 2 - 2
src/civetweb.c

@@ -4833,8 +4833,8 @@ mg_opendir(const struct mg_connection *conn, const char *name)
 	} else {
 		path_to_unicode(conn, name, wpath, ARRAY_SIZE(wpath));
 		attrs = GetFileAttributesW(wpath);
-		if (attrs != 0xFFFFFFFF && ((attrs & FILE_ATTRIBUTE_DIRECTORY)
-		                            == FILE_ATTRIBUTE_DIRECTORY)) {
+		if ((wcslen(wpath) + 2 < ARRAY_SIZE(wpath)) && (attrs != 0xFFFFFFFF)
+		    && ((attrs & FILE_ATTRIBUTE_DIRECTORY) != 0)) {
 			(void)wcscat(wpath, L"\\*");
 			dir->handle = FindFirstFileW(wpath, &dir->info);
 			dir->result.d_name[0] = '\0';