Skip to content

Commit f453d64

Browse files
bsdimpigaw
authored andcommitted
solidigm: Eliminate <linux/limits.h>
ARG_MAX is defined in <limits.h>, 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 <linux/limits.h>. With this we can delete it both places. Signed-off-by: Warner Losh <imp@bsdimp.com>
1 parent 3d53db9 commit f453d64

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

plugins/solidigm/solidigm-internal-logs.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <stdlib.h>
1313
#include <unistd.h>
1414
#include <inttypes.h>
15-
#include <linux/limits.h>
1615
#include <time.h>
1716

1817
#include "common.h"
@@ -638,25 +637,35 @@ int solidigm_get_internal_log(int argc, char **argv, struct command *command,
638637

639638
if (log_count > 0) {
640639
int ret_cmd;
641-
char cmd[ARG_MAX];
640+
char *cmd;
642641
char *quiet = cfg.verbose ? "" : " -q";
643642

644643
snprintf(zip_name, sizeof(zip_name), "%s.zip", unique_folder);
645-
snprintf(cmd, sizeof(cmd), "cd \"%s\" && zip -MM -r \"../%s\" ./* %s", cfg.out_dir,
646-
zip_name, quiet);
644+
if (asprintf(&cmd, "cd \"%s\" && zip -MM -r \"../%s\" ./* %s", cfg.out_dir,
645+
zip_name, quiet) < 0) {
646+
err = errno;
647+
perror("Can't allocate string for zip command");
648+
goto out;
649+
}
647650
printf("Compressing logs to %s\n", zip_name);
648651
ret_cmd = system(cmd);
649652
if (ret_cmd)
650653
perror(cmd);
651654
else {
652655
output_path = zip_name;
653-
snprintf(cmd, sizeof(cmd), "rm -rf %s", cfg.out_dir);
654-
printf("Removing %s\n", cfg.out_dir);
656+
free(cmd);
657+
if (asprintf(&cmd, "rm -rf %s", cfg.out_dir) < 0) {
658+
err = errno;
659+
perror("Can't allocate string for cleanup");
660+
goto out;
661+
}
655662
if (system(cmd) != 0)
656663
perror("Failed removing logs folder");
657664
}
665+
free(cmd);
658666
}
659667

668+
out:
660669
if (log_count == 0) {
661670
if (err > 0)
662671
nvme_show_status(err);

plugins/solidigm/solidigm-market-log.c

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <stdlib.h>
1313
#include <unistd.h>
1414
#include <inttypes.h>
15-
#include <linux/limits.h>
1615

1716
#include "common.h"
1817
#include "nvme.h"

0 commit comments

Comments
 (0)