From: Steinar H. Gunderson Date: Fri, 21 Dec 2018 23:13:46 +0000 (+0100) Subject: Avoid a time-to-check-versus-time-of-use error on mkdir(). X-Git-Tag: 1.8.1~45 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=b168e72fcdcd17be5c578f2232e40c2347c3ff98 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. --- 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();