diff --git a/coreutils/rm.c b/coreutils/rm.c index bb6ab12..cc5f539 100644 --- a/coreutils/rm.c +++ b/coreutils/rm.c @@ -39,13 +39,14 @@ int rmtree(const char *path) { if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, "..")) continue; + size_t len = strlen(path) + strlen(ep->d_name) + 2; char *full_path = malloc(strlen(path) + strlen(ep->d_name) + 1); if (full_path == NULL) { fprintf(stderr, "rm: malloc() returned NULL\n"); return 1; } - sprintf(full_path, "%s/%s", path, ep->d_name); + snprintf(full_path, len, "%s/%s", path, ep->d_name); rmtree(full_path); free(full_path);