From d3a8692b15003ba07a46fd3326b629e4b37f23a5 Mon Sep 17 00:00:00 2001 From: Martin Read Date: Tue, 18 Feb 2014 22:37:29 +0000 Subject: [PATCH] Fixed bug G-1 * util.c: my_makepath() was not correctly reinstating the temporarily overwritten path separator character, resulting in premature return if multiple levels of the target were incoherent. --- util.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/util.c b/util.c index d2f3d38..0c666cc 100644 --- a/util.c +++ b/util.c @@ -229,7 +229,7 @@ int my_makepath(char const *path, int mode) fprintf(stderr, "my_makepath(\"%s\", %d)\n", path, mode); #endif char *realpath = strdup(path); - char *pathtrak = ((realpath[0] == '/') ? realpath + 1 : realpath); + char *pathtrak = ((realpath[0] == UTIL_PATHSEP_CHAR) ? realpath + 1 : realpath); /* this will FUBAR on Windows, but since I'm not responsible for the * Windows port, whoever *is* responsible for the Windows port can have * the pleasure of figuring out how to do the equivalent job. */ @@ -238,28 +238,28 @@ int my_makepath(char const *path, int mode) { struct stat s; int i; - pathtrak = strchr(pathtrak, '/'); + pathtrak = strchr(pathtrak, UTIL_PATHSEP_CHAR); if (pathtrak) { pathtrak[0] = '\0'; #ifdef UTIL_DEBUG - fprintf(stderr, "Checking %s (pathtrak offset %d)\n", realpath, (int) (pathtrak - realpath)); + fprintf(stderr, "%d Checking %s (pathtrak offset %d)\n", __LINE__, realpath, (int) (pathtrak - realpath)); #endif i = stat(realpath, &s); if (i == 0) { #ifdef UTIL_DEBUG - fprintf(stderr, "stat(\"%s\") returned 0\n", realpath); + fprintf(stderr, "%d stat(\"%s\") returned 0\n", __LINE__, realpath); #endif if ((s.st_mode & S_IFMT) == S_IFDIR) { - pathtrak[0] = '/'; + pathtrak[0] = UTIL_PATHSEP_CHAR; ++pathtrak; } else { #ifdef UTIL_DEBUG - fprintf(stderr, "not a directory\n"); + fprintf(stderr, "%d not a directory\n", __LINE__); #endif errno = ENOTDIR; rv = -1; @@ -269,23 +269,25 @@ int my_makepath(char const *path, int mode) else { #ifdef UTIL_DEBUG - fprintf(stderr, "stat(\"%s\") returned %d, errno %d (%s)\n", - realpath, i, errno, strerror(errno)); + fprintf(stderr, "%d stat(\"%s\") returned %d, errno %d (%s)\n", + __LINE__, realpath, i, errno, strerror(errno)); #endif if (errno == ENOENT) { #ifdef UTIL_DEBUG - fprintf(stderr, "mkdir(\"%s\", %d)\n", realpath, mode); + fprintf(stderr, "%d mkdir(\"%s\", %d)\n", __LINE__, realpath, mode); #endif i = mkdir(realpath, mode); if (i != 0) { #ifdef UTIL_DEBUG - fprintf(stderr, "mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", realpath, mode, i, errno, strerror(errno)); + fprintf(stderr, "%d mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", __LINE__, realpath, mode, i, errno, strerror(errno)); #endif rv = -1; break; } + pathtrak[0] = UTIL_PATHSEP_CHAR; + ++pathtrak; } } } @@ -295,7 +297,7 @@ int my_makepath(char const *path, int mode) if (i == 0) { #ifdef UTIL_DEBUG - fprintf(stderr, "stat(\"%s\") returned 0\n", realpath); + fprintf(stderr, "%d stat(\"%s\") returned 0\n", __LINE__, realpath); #endif if ((s.st_mode & S_IFMT) == S_IFDIR) { @@ -315,18 +317,19 @@ int my_makepath(char const *path, int mode) if (errno == ENOENT) { #ifdef UTIL_DEBUG - fprintf(stderr, "mkdir(\"%s\", %d)\n", realpath, mode); + fprintf(stderr, "%d mkdir(\"%s\", %d)\n", __LINE__, realpath, mode); #endif i = mkdir(realpath, mode); if (i != 0) { #ifdef UTIL_DEBUG - fprintf(stderr, "mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", realpath, mode, i, errno, strerror(errno)); + fprintf(stderr, "%d mkdir(\"%s\", %d) returned %d, errno %d (%s)\n", __LINE__, realpath, mode, i, errno, strerror(errno)); #endif rv = -1; } else { + fprintf(stderr, "%d mkdir(\"%s\", %d) returned 0\n", __LINE__, realpath, mode); rv = 0; } } @@ -338,6 +341,10 @@ int my_makepath(char const *path, int mode) } /*! \brief compose a directory suffix from a vendor name and an app name + * + * \todo include proper sanitization of vendor and app strings + * \param vendor "Vendor name" to use in suffix + * \param app "Application name" to use in suffix */ static char *app_suffix(char const *vendor, char const *app) { @@ -351,7 +358,7 @@ static char *app_suffix(char const *vendor, char const *app) errno = EINVAL; return NULL; } - // TODO include proper sanitization of vendor and app strings + // TODO s1 = strlen(vendor); s2 = strlen(UTIL_PATHSEP_STRING); s3 = strlen(app); -- 2.11.0