diff --git a/test/opener/opener.c b/test/opener/opener.c index 51ce934..e6d9231 100644 --- a/test/opener/opener.c +++ b/test/opener/opener.c @@ -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;