Overview
Comment: | Don't use readdir_r
readdir_r can easily lead to stack overflows if the path is longer than |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
c615b62ed8dfcdb37ded7c7a8b2c63d1 |
User & Date: | js on 2024-04-16 23:50:40 |
Other Links: | manifest | tags |
Context
2024-04-17
| ||
20:45 | forwarding: Don't grow the stack twice on ARM64 check-in: 8e95cb1c77 user: js tags: trunk | |
2024-04-16
| ||
23:50 | Don't use readdir_r check-in: c615b62ed8 user: js tags: trunk | |
23:18 | lookup-asm-arm64-elf.S: Save one instruction check-in: 460b84b9b2 user: js tags: trunk | |
Changes
Modified configure.ac from [fa7714f07b] to [63f2b5a434].
︙ | ︙ | |||
1280 1281 1282 1283 1284 1285 1286 | AC_CHECK_FUNC(symlink, [ AC_DEFINE(OF_HAVE_SYMLINK, 1, [Whether we have symlink()]) ]) AC_CHECK_FUNCS([lstat]) AC_CHECK_MEMBERS([struct stat.st_birthtime], [], [], [ #include <sys/stat.h> ]) | < < < < < < < < < < < < < < < < < < < < | 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | AC_CHECK_FUNC(symlink, [ AC_DEFINE(OF_HAVE_SYMLINK, 1, [Whether we have symlink()]) ]) AC_CHECK_FUNCS([lstat]) AC_CHECK_MEMBERS([struct stat.st_birthtime], [], [], [ #include <sys/stat.h> ]) ]) AC_CHECK_HEADERS(dirent.h) AC_CHECK_FUNCS([sysconf gmtime_r localtime_r]) case "$host_os" in amigaos* | morphos*) |
︙ | ︙ |
Modified src/OFFileIRIHandler.m from [ef59c89349] to [d9639e50f4].
︙ | ︙ | |||
136 137 138 139 140 141 142 | static void releasePasswdMutex(void) { [passwdMutex release]; } #endif | | | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | static void releasePasswdMutex(void) { [passwdMutex release]; } #endif #if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) && !defined(OF_WINDOWS) static OFMutex *readdirMutex; static void releaseReaddirMutex(void) { [readdirMutex release]; } |
︙ | ︙ | |||
771 772 773 774 775 776 777 | if (self != [OFFileIRIHandler class]) return; #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) passwdMutex = [[OFMutex alloc] init]; atexit(releasePasswdMutex); #endif | | | 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | if (self != [OFFileIRIHandler class]) return; #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) passwdMutex = [[OFMutex alloc] init]; atexit(releasePasswdMutex); #endif #if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) && !defined(OF_WINDOWS) readdirMutex = [[OFMutex alloc] init]; atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS if ((module = GetModuleHandle("msvcrt.dll")) != NULL) _wutime64FuncPtr = (int (*)(const wchar_t *, |
︙ | ︙ | |||
1418 1419 1420 1421 1422 1423 1424 | OFStringEncoding encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: errno]; | | < < < < < < < < < < < < < < | | 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 | OFStringEncoding encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithIRI: IRI mode: nil errNo: errno]; # if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) @try { [readdirMutex lock]; } @catch (id e) { closedir(dir); @throw e; } # endif @try { for (;;) { struct dirent *dirent; OFString *file; errno = 0; if ((dirent = readdir(dir)) == NULL) { if (errno == 0) break; else @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: errno]; } if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { [IRIs addObject: [IRI IRIByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { closedir(dir); # if defined(OF_HAVE_THREADS) && !defined(__GLIBC__) [readdirMutex unlock]; # endif } #endif [IRIs makeImmutable]; |
︙ | ︙ |