Skip to contentSkip to conversation

app/wycheproof: avoid path check before opening vectors

PATCH Applied Kai Ji 2 participants 2 messages Nov 17 – Nov 19

lore
Share & tools
lore

Kai Ji

author
#0 lore raw

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

---
 app/wycheproof_validation/main.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
app/wycheproof_validation/main.c +4 -8
index 9b8182f15b..41ae182803 100644
@@ -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
#1 lore raw

17/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

Applied, thanks.