Differences From Artifact [ef59c89349]:
- File src/OFFileIRIHandler.m — part of check-in [51dfaf9042] at 2024-04-14 18:55:45 on branch trunk — OFFileIRIHandler: Fix missing variable on Haiku (user: js, size: 50568) [annotate] [blame] [check-ins using]
To Artifact [d9639e50f4]:
- File
src/OFFileIRIHandler.m
— part of check-in
[c615b62ed8]
at
2024-04-16 23:50:40
on branch trunk
— Don't use readdir_r
readdir_r can easily lead to stack overflows if the path is longer than
the space reserved for d_name in dirent. While some OSes use a length of
MAXNAMLEN + 1, others use just 1. This could be worked around by always
allocating a buffer of sizeof(struct dirent) + MAXNAMLEN (which would
work only in case MAXNAMLEN is actually the longest readdir_r can
return), but is probably not worth the risk, especially as glibc has
entirely deprecated readdir_r and it is expected to be removed from
POSIX. (user: js, size: 50258) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
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]; |
︙ | ︙ |