access + mkdir: a time-of-check, time-of-use race condition #2739
Labels
Comments
The question is what a decent fix would be. I'm thinking:
Then, if the mkdir() fails for another reason but the path is a directory, that's still fine. |
Thanks @bagder |
yes easiest way i think is check EEXIST diff --git a/src/tool_dirhie.c b/src/tool_dirhie.c
index a01f9dc..5755823 100644
--- a/src/tool_dirhie.c
+++ b/src/tool_dirhie.c
@@ -139,12 +139,10 @@ CURLcode create_dir_hierarchy(const char *outfile, FILE *e
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; |
Right, so someone needs to make a PR out of it... |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Detected by Coverity.
The text was updated successfully, but these errors were encountered: