From 6082040a5178a3741f4fb065c857f1457e2fc4c6 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 21 Sep 2014 02:17:32 +0200 Subject: common: Fix possible crash in mkdir_with_parents() --- src/common.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/common.c b/src/common.c index 7646361..49df778 100644 --- a/src/common.c +++ b/src/common.c @@ -234,13 +234,19 @@ int mkdir_with_parents(const char *dir, int mode) if (__mkdir(dir, mode) == 0) { return 0; } else { - if (errno == EEXIST) return 0; + if (errno == EEXIST) { + return 0; + } else if (errno == ENOENT) { + // ignore + } else { + return -1; + } } int res; char *parent = strdup(dir); - parent = dirname(parent); - if (parent && (strcmp(parent, ".") != 0) && (strcmp(parent, dir) != 0)) { - res = mkdir_with_parents(parent, mode); + char *parentdir = dirname(parent); + if (parentdir && (strcmp(parentdir, ".") != 0) && (strcmp(parentdir, dir) != 0)) { + res = mkdir_with_parents(parentdir, mode); } else { res = -1; } @@ -287,4 +293,4 @@ void plist_dict_merge(plist_t* dictionary, plist_t node) plist_dict_next_item(node, it, &key, &subnode); } free(it); -} \ No newline at end of file +} -- cgit v1.1-32-gdbae