app/wycheproof: avoid path check before opening vectors
PATCH 1/1 app/wycheproof: avoid path check before opening vectors
Checking the vector path with stat() before opening it leaves a check/use race if the path changes between the two operations.
Open the directory directly and fall back to file processing only when opendir() fails with ENOTDIR. Propagate other directory-open errors and remove the unused stat header.
Coverity issue: 360736
Signed-off-by Kai Ji <[email protected]>
--- app/wycheproof_validation/main.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
app/wycheproof_validation/main.c +4 -8
@@ -12,7 +12,6 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/stat.h> #include <jansson.h>
@@ -2031,19 +2030,16 @@ process_file(const char *path, struct app_stats *stats)static int process_path (const char *path,struct app_stats *stats) { -struct stat path_stat;DIR *directory;struct dirent *entry;int ret =0 ; -if (stat (path, &path_stat) !=0 ) -return -errno; -if (!S_ISDIR (path_stat.st_mode)) -return process_file (path, stats); - directory =opendir (path); -if (directory ==NULL ) +if (directory ==NULL ) { +if (errno ==ENOTDIR ) +return process_file (path, stats);return -errno; + }while ((entry =readdir (directory)) !=NULL ) {char file_path[PATH_MAX ];size_t name_length =strlen (entry->d_name);
Signature · 1 line
2.34.1
Thomas Monjalon
Applied17/11/2026 16:49, Kai Ji:
Quoted 10 lines
Checking the vector path with
stat()before opening it leaves a check/use race if the path changes between the two operations.Open the directory directly and fall back to file processing only when
opendir()fails with ENOTDIR. Propagate other directory-open errors and remove the unused stat header.Coverity issue: 360736
Signed-off-by Kai Ji <[email protected]>
Applied, thanks.