Fixed buffer overflow

This commit is contained in:
fedir 2025-06-23 20:56:03 +02:00
parent ea2e41693c
commit 91621605b1
Signed by: fedir
GPG Key ID: C959EE85F0C9362C

View File

@ -54,24 +54,32 @@ int main(int argc, char *argv[]) {
}
// Construct the full path
char fullpath[PATH_MAX];
snprintf(fullpath, PATH_MAX, "%s/%s", path, entry->d_name);
char *fullpath = NULL;
if (asprintf(&fullpath, "%s/%s", path, entry->d_name) == -1 ||
fullpath == NULL) {
perror("asprintf");
success = 0;
break;
}
// Stat the entry to check if it's a regular file
struct stat entry_stat;
if (lstat(fullpath, &entry_stat) == -1) {
perror("lstat");
success = 0;
free(fullpath);
break;
}
// Only process regular files
if (!S_ISREG(entry_stat.st_mode)) {
free(fullpath);
continue;
}
// Try to open and immediately close the file
int fd = open(fullpath, O_RDONLY);
free(fullpath);
if (fd == -1) {
perror("open");
success = 0;