|
|
fffb44 |
From 625f4b9aacfa7fa226949c8d5a36c298196432ea Mon Sep 17 00:00:00 2001
|
|
|
fffb44 |
From: Tomas Heinrich <theinric@redhat.com>
|
|
|
fffb44 |
Date: Wed, 8 Jul 2015 17:16:46 +0200
|
|
|
fffb44 |
Subject: [PATCH] Fix race-condition detection in path-creation code
|
|
|
fffb44 |
|
|
|
fffb44 |
The affected code is used to detect a race condition in between
|
|
|
fffb44 |
testing for the existence of a directory and creating it if it didn't
|
|
|
fffb44 |
exist. The variable tracking the number of attempts wasn't reset for
|
|
|
fffb44 |
subsequent elements in the path, thus limiting the number of
|
|
|
fffb44 |
reattempts to one per the whole path, instead of one per each path
|
|
|
fffb44 |
element.
|
|
|
fffb44 |
|
|
|
fffb44 |
It appears the detection never actually worked due to wrong error
|
|
|
fffb44 |
checking. errno needs to be checked to determin the reason for the
|
|
|
fffb44 |
failure.
|
|
|
fffb44 |
---
|
|
|
fffb44 |
runtime/srutils.c | 6 +++---
|
|
|
fffb44 |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
fffb44 |
|
|
|
fffb44 |
diff --git a/runtime/srutils.c b/runtime/srutils.c
|
|
|
fffb44 |
index 6a509b4..e66c1cd 100644
|
|
|
fffb44 |
--- a/runtime/srutils.c
|
|
|
fffb44 |
+++ b/runtime/srutils.c
|
|
|
fffb44 |
@@ -195,7 +195,6 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
|
|
|
fffb44 |
uchar *p;
|
|
|
fffb44 |
uchar *pszWork;
|
|
|
fffb44 |
size_t len;
|
|
|
fffb44 |
- int err;
|
|
|
fffb44 |
int iTry = 0;
|
|
|
fffb44 |
int bErr = 0;
|
|
|
fffb44 |
|
|
|
fffb44 |
@@ -210,9 +209,10 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
|
|
|
fffb44 |
if(*p == '/') {
|
|
|
fffb44 |
/* temporarily terminate string, create dir and go on */
|
|
|
fffb44 |
*p = '\0';
|
|
|
fffb44 |
+ iTry = 0;
|
|
|
fffb44 |
again:
|
|
|
fffb44 |
if(access((char*)pszWork, F_OK)) {
|
|
|
fffb44 |
- if((err = mkdir((char*)pszWork, mode)) == 0) {
|
|
|
fffb44 |
+ if(mkdir((char*)pszWork, mode) == 0) {
|
|
|
fffb44 |
if(uid != (uid_t) -1 || gid != (gid_t) -1) {
|
|
|
fffb44 |
/* we need to set owner/group */
|
|
|
fffb44 |
if(chown((char*)pszWork, uid, gid) != 0)
|
|
|
fffb44 |
@@ -223,7 +223,7 @@ again:
|
|
|
fffb44 |
*/
|
|
|
fffb44 |
}
|
|
|
fffb44 |
} else {
|
|
|
fffb44 |
- if(err == EEXIST && iTry == 0) {
|
|
|
fffb44 |
+ if(errno == EEXIST && iTry == 0) {
|
|
|
fffb44 |
iTry = 1;
|
|
|
fffb44 |
goto again;
|
|
|
fffb44 |
}
|
|
|
fffb44 |
--
|
|
|
fffb44 |
1.9.3
|
|
|
fffb44 |
|