diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-09-02 07:11:04 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-09-02 07:11:04 +0000 |
commit | b167ced1561d8c6ad872c2522b1894f9a5b37f48 (patch) | |
tree | 1d10c53a3d6afdaf4e83ba66ccbea711036fe958 | |
parent | 19586fff8fadddacfc230f5dd857001cf80ae61e (diff) |
Change copying arguments to that flags without arguments are inserted
correctly and empty arguments lists do not crash. Fixes crash reported
by & ok mpi@.
-rw-r--r-- | usr.bin/tmux/arguments.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index a8ed55b7c9c..226617014f4 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.48 2021/08/27 17:25:55 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.49 2021/09/02 07:11:03 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -302,10 +302,13 @@ args_copy(struct args *args, int argc, char **argv) struct args_value *value, *new_value; u_int i; + cmd_log_argv(argc, argv, "%s", __func__); + new_args = args_create(); RB_FOREACH(entry, args_tree, &args->tree) { - if (entry->count == 1) { - args_set(new_args, entry->flag, NULL); + if (TAILQ_EMPTY(&entry->values)) { + for (i = 0; i < entry->count; i++) + args_set(new_args, entry->flag, NULL); continue; } TAILQ_FOREACH(value, &entry->values, entry) { @@ -314,6 +317,8 @@ args_copy(struct args *args, int argc, char **argv) args_set(new_args, entry->flag, new_value); } } + if (args->count == 0) + return (new_args); new_args->count = args->count; new_args->values = xcalloc(args->count, sizeof *new_args->values); for (i = 0; i < args->count; i++) { |