From d840baba076a12e36ee65fabe4aaf1102e1bfe3d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 20 Oct 2023 18:45:10 +0300 Subject: [PATCH] Fix recursion in rm --- coreutils/cp.c | 2 +- coreutils/mkdir.c | 2 +- coreutils/rm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coreutils/cp.c b/coreutils/cp.c index b4daa95..71265e6 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c @@ -88,7 +88,7 @@ int cptree(const char *src, const char *dst) { if (get_stat(src, &stat_path)) return 1; - if (S_ISDIR(stat_path.st_mode) == 0) { + if (!S_ISDIR(stat_path.st_mode)) { if (copy(src, dst)) { fprintf(stderr, "cp: %s: copy() failed (%s)\n", src, strerror(errno)); return 1; diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index 18b71c4..7390a5b 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c @@ -44,7 +44,7 @@ int main(const int argc, const char **argv) { flag = 1; else if (!strcmp(argv[i], "-h")) { - printf("mkdir [-p (make parent dir)] [dir1 dir2...]"); + printf("mkdir [-p (make parent dir)] [dir1 dir2...]\n"); return 0; } } diff --git a/coreutils/rm.c b/coreutils/rm.c index fb87234..fba5a4e 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -41,7 +41,7 @@ int rmtree(const char *path) { continue; size_t len = strlen(path) + strlen(ep->d_name) + 2; - char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1); + char *full_path = malloc(len + 1); if (full_path == NULL) { fprintf(stderr, "rm: malloc() returned NULL\n"); return 1;