summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-09-21 02:17:32 +0200
committerGravatar Nikias Bassen2014-09-21 02:17:32 +0200
commit6082040a5178a3741f4fb065c857f1457e2fc4c6 (patch)
treeb5c5117e6d0c85f1034b4fcd7abe0f6cf53051d2 /src
parent704afa39c66a6e912f509112f543010b8234ec4d (diff)
downloadidevicerestore-6082040a5178a3741f4fb065c857f1457e2fc4c6.tar.gz
idevicerestore-6082040a5178a3741f4fb065c857f1457e2fc4c6.tar.bz2
common: Fix possible crash in mkdir_with_parents()
Diffstat (limited to 'src')
-rw-r--r--src/common.c16
1 files 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
+}