From a0a4e88f727fe0cb76ed6cef1b7f00d9e396b555 Mon Sep 17 00:00:00 2001 From: petershh Date: Mon, 11 Jul 2022 15:50:51 +0300 Subject: chmod: fix faulty logic --- src/shh-portable-utils/chmod.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/shh-portable-utils/chmod.c b/src/shh-portable-utils/chmod.c index cce6844..0995419 100644 --- a/src/shh-portable-utils/chmod.c +++ b/src/shh-portable-utils/chmod.c @@ -87,7 +87,11 @@ int main(int argc, char const *const *argv) } if (S_ISDIR(st.st_mode) && recurse) { satmp.len = 0; - stralloc_catb(&satmp, *filename, strlen(*filename) + 1); + if (!stralloc_catb(&satmp, *filename, strlen(*filename) + 1)) { + strerr_warnwu2sys("build file name ", *filename); + failure = 1; + continue; + } failure = failure || traverse_dir(&satmp, mode, &directives, mask); } @@ -354,12 +358,10 @@ int traverse_dir(stralloc *dirname, mode_t mode, genalloc *directives, entry->d_name); failure = 1; continue; - } - if (stat(dirname->s, &st) == -1) { + } else if (stat(dirname->s, &st) == -1) { strerr_warnwu2sys("stat ", dirname->s); failure = 1; - } - if (S_ISDIR(st.st_mode)) + } else if (S_ISDIR(st.st_mode)) failure = failure || traverse_dir(dirname, mode, directives, mask); else failure = failure || change_mode(dirname->s, mode, directives, -- cgit v1.2.3