diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-06-20 17:32:24 -0300 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-10-19 10:56:54 +0200 |
commit | a0aa59b9a09ef4688510d345092f6c5292046cfc (patch) | |
tree | 014d91db8f6958bbf62b62ebf54d7bc9657251e8 /src | |
parent | 2799ba1d14aceabf0a9863fc12ffa5c037d5ef8a (diff) |
librc.c: fix potential infinite loop in recusive_mkdir
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src')
-rw-r--r-- | src/librc/librc.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/librc/librc.c b/src/librc/librc.c index 53625759..9d9e7461 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -133,15 +133,13 @@ recursive_mkdir(const char *pathname, int mode) return 0; } - for (p = dir + 1; p; p++) { - if (*p == '/') { - *p = '\0'; - if (mkdir(dir, mode) != 0 && errno != EEXIST) { - free(dir); - return -1; - } - *p = '/'; + for (p = strchr(dir + 1, '/'); p; p = strchr(p + 1, '/')) { + *p = '\0'; + if (mkdir(dir, mode) != 0 && errno != EEXIST) { + free(dir); + return -1; } + *p = '/'; } if (stat(dir, &sb) != 0) { |