Blob Blame History Raw
From 625f4b9aacfa7fa226949c8d5a36c298196432ea Mon Sep 17 00:00:00 2001
From: Tomas Heinrich <theinric@redhat.com>
Date: Wed, 8 Jul 2015 17:16:46 +0200
Subject: [PATCH] Fix race-condition detection in path-creation code

The affected code is used to detect a race condition in between
testing for the existence of a directory and creating it if it didn't
exist.  The variable tracking the number of attempts wasn't reset for
subsequent elements in the path, thus limiting the number of
reattempts to one per the whole path, instead of one per each path
element.

It appears the detection never actually worked due to wrong error
checking. errno needs to be checked to determin the reason for the
failure.
---
 runtime/srutils.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/runtime/srutils.c b/runtime/srutils.c
index 6a509b4..e66c1cd 100644
--- a/runtime/srutils.c
+++ b/runtime/srutils.c
@@ -195,7 +195,6 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
         uchar *p;
         uchar *pszWork;
         size_t len;
-	int err;
 	int iTry = 0;
 	int bErr = 0;
 
@@ -210,9 +209,10 @@ int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode,
                 if(*p == '/') {
 			/* temporarily terminate string, create dir and go on */
                         *p = '\0';
+			iTry = 0;
 again:
                         if(access((char*)pszWork, F_OK)) {
-                                if((err = mkdir((char*)pszWork, mode)) == 0) {
+                                if(mkdir((char*)pszWork, mode) == 0) {
 					if(uid != (uid_t) -1 || gid != (gid_t) -1) {
 						/* we need to set owner/group */
 						if(chown((char*)pszWork, uid, gid) != 0)
@@ -223,7 +223,7 @@ again:
 							 */
 					}
 				} else {
-					if(err == EEXIST && iTry == 0) {
+					if(errno == EEXIST && iTry == 0) {
 						iTry = 1;
 						goto again;
 						}
-- 
1.9.3