From b168e72fcdcd17be5c578f2232e40c2347c3ff98 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 22 Dec 2018 00:13:46 +0100 Subject: [PATCH] Avoid a time-to-check-versus-time-of-use error on mkdir(). Found by Coverity Scan. Not relevant in practice, since we do not support running on untrusted data. --- futatabi/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/futatabi/main.cpp b/futatabi/main.cpp index 33a486a..3146aa5 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -200,13 +200,11 @@ int main(int argc, char **argv) string frame_dir = global_flags.working_directory + "/frames"; - struct stat st; - if (stat(frame_dir.c_str(), &st) == -1) { + if (mkdir(frame_dir.c_str(), 0777) == 0) { fprintf(stderr, "%s does not exist, creating it.\n", frame_dir.c_str()); - if (mkdir(frame_dir.c_str(), 0777) == -1) { - perror(global_flags.working_directory.c_str()); - exit(1); - } + } else if (errno != EEXIST) { + perror(global_flags.working_directory.c_str()); + exit(1); } avformat_network_init(); -- 2.39.2