summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-string.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2009-11-11 18:56:07 +0000
committernicm <nicm@openbsd.org>2009-11-11 18:56:07 +0000
commitffa9154148283f2a71615929f80386df3157ea6a (patch)
treee3ba8099112c0f7b5fc47c17dad82681e8f438da /usr.bin/tmux/cmd-string.c
parentAdd an explicit zero-length check for UTF-8 input data, prompted by a report (diff)
downloadwireguard-openbsd-ffa9154148283f2a71615929f80386df3157ea6a.tar.xz
wireguard-openbsd-ffa9154148283f2a71615929f80386df3157ea6a.zip
Rewrite a confusing loop when freeing the arg array on exit and move the check
for argv being NULL, prompted by parfait via deraadt. Also fix some definite brokenness when assigning multiple environment variables in arguments (such as "X=1 Y=2").
Diffstat (limited to 'usr.bin/tmux/cmd-string.c')
-rw-r--r--usr.bin/tmux/cmd-string.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c
index 19f43e1d2ef..a2f4e01bdaa 100644
--- a/usr.bin/tmux/cmd-string.c
+++ b/usr.bin/tmux/cmd-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-string.c,v 1.7 2009/10/26 21:42:04 deraadt Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.8 2009/11/11 18:56:07 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -134,17 +134,15 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
if (ch != EOF)
break;
- if (argc == 0)
- goto out;
- for (i = 0; i < argc; i++) {
- equals = strchr(argv[i], '=');
- whitespace = argv[i] + strcspn(argv[i], " \t");
+ while (argc != 0) {
+ equals = strchr(argv[0], '=');
+ whitespace = argv[0] + strcspn(argv[0], " \t");
if (equals == NULL || equals > whitespace)
break;
- environ_put(&global_environ, argv[i]);
- memmove(&argv[i], &argv[i + 1], argc - i - 1);
+ environ_put(&global_environ, argv[0]);
argc--;
+ memmove(argv, argv + 1, argc * (sizeof *argv));
}
if (argc == 0)
goto out;
@@ -189,10 +187,11 @@ out:
if (buf != NULL)
xfree(buf);
- while (--argc >= 0)
- xfree(argv[argc]);
- if (argv != NULL)
+ if (argv != NULL) {
+ for (i = 0; i < argc; i++)
+ xfree(argv[argc]);
xfree(argv);
+ }
return (rval);
}