Skip to content

Commit

Permalink
librc.c: fix potential infinite loop in recusive_mkdir
Browse files Browse the repository at this point in the history
Signed-off-by: Anna (navi) Figueiredo Gomes <[email protected]>
  • Loading branch information
navi-desu committed Jun 20, 2023
1 parent 5bddd26 commit e12ddac
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/librc/librc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e12ddac

Please sign in to comment.