curl: fix time-of-check, time-of-use race in dir creation

Patch-by: Jay Satiro
Detected by Coverity
Fixes #2739
Closes #2912
This commit is contained in:
Daniel Stenberg 2018-08-24 10:01:42 +02:00
parent 2345388728
commit f16bed0c45
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
1 changed files with 4 additions and 6 deletions

View File

@ -139,12 +139,10 @@ CURLcode create_dir_hierarchy(const char *outfile, FILE *errors)
else
snprintf(dirbuildup, outlen, "%s%s", DIR_CHAR, tempdir);
}
if(access(dirbuildup, F_OK) == -1) {
if(-1 == mkdir(dirbuildup, (mode_t)0000750)) {
show_dir_errno(errors, dirbuildup);
result = CURLE_WRITE_ERROR;
break; /* get out of loop */
}
if((-1 == mkdir(dirbuildup, (mode_t)0000750)) && (errno != EEXIST)) {
show_dir_errno(errors, dirbuildup);
result = CURLE_WRITE_ERROR;
break; /* get out of loop */
}
}
tempdir = tempdir2;