[PATCH] app/wycheproof: avoid path check before opening vectors

Kai Ji kai.ji at intel.com
Tue Nov 17 16:49:49 CET 2026


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 <kai.ji at intel.com>
---
 app/wycheproof_validation/main.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/app/wycheproof_validation/main.c b/app/wycheproof_validation/main.c
index 9b8182f15b..41ae182803 100644
--- a/app/wycheproof_validation/main.c
+++ b/app/wycheproof_validation/main.c
@@ -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);
-- 
2.34.1



More information about the dev mailing list