From a0aa59b9a09ef4688510d345092f6c5292046cfc Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Tue, 20 Jun 2023 17:32:24 -0300 Subject: librc.c: fix potential infinite loop in recusive_mkdir Signed-off-by: Anna (navi) Figueiredo Gomes --- src/librc/librc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/librc') 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) { -- cgit v1.2.3