summaryrefslogtreecommitdiffstats
path: root/cmd/zpool
diff options
context:
space:
mode:
authorDeHackEd <[email protected]>2018-08-20 12:55:18 -0400
committerTony Hutter <[email protected]>2018-07-06 02:46:51 -0700
commit778290d5bcc33ec0b6164766049cdb9ad06f7f20 (patch)
treecfdf3e1c037b281ff47e769d98d3ea38343e597b /cmd/zpool
parent98bc8e0b236174e2f9b877006832b053212ffaca (diff)
Don't modify argv[] in user tools
argv[] gets modified during string parsing for input arguments. This is reflected in the live process listing. Don't do that. Reviewed-by: Serapheim Dimitropoulos <[email protected]> Reviewed-by: loli10K <[email protected]> Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: George Melikov <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: DHE <[email protected]> Closes #7760
Diffstat (limited to 'cmd/zpool')
-rw-r--r--cmd/zpool/zpool_main.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c
index 976970112..a4fd03212 100644
--- a/cmd/zpool/zpool_main.c
+++ b/cmd/zpool/zpool_main.c
@@ -7971,6 +7971,7 @@ main(int argc, char **argv)
int ret = 0;
int i = 0;
char *cmdname;
+ char **newargv;
(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
@@ -8006,15 +8007,24 @@ main(int argc, char **argv)
zfs_save_arguments(argc, argv, history_str, sizeof (history_str));
/*
+ * Many commands modify input strings for string parsing reasons.
+ * We create a copy to protect the original argv.
+ */
+ newargv = malloc((argc + 1) * sizeof (newargv[0]));
+ for (i = 0; i < argc; i++)
+ newargv[i] = strdup(argv[i]);
+ newargv[argc] = NULL;
+
+ /*
* Run the appropriate command.
*/
if (find_command_idx(cmdname, &i) == 0) {
current_command = &command_table[i];
- ret = command_table[i].func(argc - 1, argv + 1);
+ ret = command_table[i].func(argc - 1, newargv + 1);
} else if (strchr(cmdname, '=')) {
verify(find_command_idx("set", &i) == 0);
current_command = &command_table[i];
- ret = command_table[i].func(argc, argv);
+ ret = command_table[i].func(argc, newargv);
} else if (strcmp(cmdname, "freeze") == 0 && argc == 3) {
/*
* 'freeze' is a vile debugging abomination, so we treat
@@ -8031,6 +8041,10 @@ main(int argc, char **argv)
ret = 1;
}
+ for (i = 0; i < argc; i++)
+ free(newargv[i]);
+ free(newargv);
+
if (ret == 0 && log_history)
(void) zpool_log_history(g_zfs, history_str);