mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-30 03:54:10 +01:00
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").
This commit is contained in:
parent
9df4e7597d
commit
89763f2ace
17
cmd-string.c
17
cmd-string.c
@ -134,17 +134,15 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
|
|||||||
|
|
||||||
if (ch != EOF)
|
if (ch != EOF)
|
||||||
break;
|
break;
|
||||||
if (argc == 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
while (argc != 0) {
|
||||||
equals = strchr(argv[i], '=');
|
equals = strchr(argv[0], '=');
|
||||||
whitespace = argv[i] + strcspn(argv[i], " \t");
|
whitespace = argv[0] + strcspn(argv[0], " \t");
|
||||||
if (equals == NULL || equals > whitespace)
|
if (equals == NULL || equals > whitespace)
|
||||||
break;
|
break;
|
||||||
environ_put(&global_environ, argv[i]);
|
environ_put(&global_environ, argv[0]);
|
||||||
memmove(&argv[i], &argv[i + 1], argc - i - 1);
|
|
||||||
argc--;
|
argc--;
|
||||||
|
memmove(argv, argv + 1, argc * (sizeof *argv));
|
||||||
}
|
}
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
goto out;
|
goto out;
|
||||||
@ -189,10 +187,11 @@ out:
|
|||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
xfree(buf);
|
xfree(buf);
|
||||||
|
|
||||||
while (--argc >= 0)
|
if (argv != NULL) {
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
xfree(argv[argc]);
|
xfree(argv[argc]);
|
||||||
if (argv != NULL)
|
|
||||||
xfree(argv);
|
xfree(argv);
|
||||||
|
}
|
||||||
|
|
||||||
return (rval);
|
return (rval);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user