From f453d64b2e8b0e6427aee9509cfd003aaae90e67 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 3 May 2024 21:32:07 -0600 Subject: [PATCH] solidigm: Eliminate ARG_MAX is defined in , per POSIX, but it's defined to be a variable in glibc. Instead, get rid of it entirely by using asprintf to construct the commands. This prevents us from trying a partially constructed command that might do something unintentional. For solidigm-market-log.c, there's no constants needed from . With this we can delete it both places. Signed-off-by: Warner Losh --- plugins/solidigm/solidigm-internal-logs.c | 21 +++++++++++++++------ plugins/solidigm/solidigm-market-log.c | 1 - 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/solidigm/solidigm-internal-logs.c b/plugins/solidigm/solidigm-internal-logs.c index 92f62a00..49a07faf 100644 --- a/plugins/solidigm/solidigm-internal-logs.c +++ b/plugins/solidigm/solidigm-internal-logs.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include "common.h" @@ -638,25 +637,35 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *command, if (log_count > 0) { int ret_cmd; - char cmd[ARG_MAX]; + char *cmd; char *quiet = cfg.verbose ? "" : " -q"; snprintf(zip_name, sizeof(zip_name), "%s.zip", unique_folder); - snprintf(cmd, sizeof(cmd), "cd \"%s\" && zip -MM -r \"../%s\" ./* %s", cfg.out_dir, - zip_name, quiet); + if (asprintf(&cmd, "cd \"%s\" && zip -MM -r \"../%s\" ./* %s", cfg.out_dir, + zip_name, quiet) < 0) { + err = errno; + perror("Can't allocate string for zip command"); + goto out; + } printf("Compressing logs to %s\n", zip_name); ret_cmd = system(cmd); if (ret_cmd) perror(cmd); else { output_path = zip_name; - snprintf(cmd, sizeof(cmd), "rm -rf %s", cfg.out_dir); - printf("Removing %s\n", cfg.out_dir); + free(cmd); + if (asprintf(&cmd, "rm -rf %s", cfg.out_dir) < 0) { + err = errno; + perror("Can't allocate string for cleanup"); + goto out; + } if (system(cmd) != 0) perror("Failed removing logs folder"); } + free(cmd); } +out: if (log_count == 0) { if (err > 0) nvme_show_status(err); diff --git a/plugins/solidigm/solidigm-market-log.c b/plugins/solidigm/solidigm-market-log.c index d7d38daa..e7e8728d 100644 --- a/plugins/solidigm/solidigm-market-log.c +++ b/plugins/solidigm/solidigm-market-log.c @@ -12,7 +12,6 @@ #include #include #include -#include #include "common.h" #include "nvme.h" -- 2.50.1