summaryrefslogtreecommitdiffstats
path: root/cmd-string.c
authortcunha <tcunha>2009-11-13 16:55:10 (GMT)
committer tcunha <tcunha>2009-11-13 16:55:10 (GMT)
commit6b2d615573f6f06d50509bfa7a2f8561f94d9d8a (patch) (side-by-side diff)
tree5617de9c4a32b73c54e890384e0e48a7c16f3676 /cmd-string.c
parentd7ffddc0350779628656482c9ce91a81f7720d8f (diff)
downloadtmux-old-6b2d615573f6f06d50509bfa7a2f8561f94d9d8a.zip
tmux-old-6b2d615573f6f06d50509bfa7a2f8561f94d9d8a.tar.gz
tmux-old-6b2d615573f6f06d50509bfa7a2f8561f94d9d8a.tar.bz2
Sync OpenBSD patchset 530:
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 'cmd-string.c') (more/less context) (ignore whitespace changes)
-rw-r--r--cmd-string.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/cmd-string.c b/cmd-string.c
index cc14893..526cea9 100644
--- a/cmd-string.c
+++ b/cmd-string.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-string.c,v 1.24 2009/10/28 23:12:38 tcunha Exp $ */
+/* $Id: cmd-string.c,v 1.25 2009/11/13 16:55:10 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <[email protected]>
@@ -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);
}