A fix from Larry Doolittle for some nasty segfaults when sh.c tried to free a

corrupted cmd pointer, and where it would truncate a command line at the first
double space.
 -Erik
This commit is contained in:
Eric Andersen 2001-03-12 21:36:49 +00:00
parent 5ec5415402
commit 4987bbf979
3 changed files with 9 additions and 9 deletions

6
lash.c
View File

@ -970,10 +970,10 @@ static int expand_arguments(char *command)
{ {
int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE; int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE;
char * tmpcmd; char * tmpcmd, *cmd, *cmd_copy;
/* We need a clean copy, so strsep can mess up the copy while /* We need a clean copy, so strsep can mess up the copy while
* we write stuff into the original (in a minute) */ * we write stuff into the original (in a minute) */
char * cmd = strdup(command); cmd = cmd_copy = strdup(command);
*command = '\0'; *command = '\0';
for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) { for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) {
if (*tmpcmd == '\0') if (*tmpcmd == '\0')
@ -1006,7 +1006,7 @@ static int expand_arguments(char *command)
globfree (&expand_result); globfree (&expand_result);
} }
} }
free(cmd); free(cmd_copy);
trim(command); trim(command);
} }

6
sh.c
View File

@ -970,10 +970,10 @@ static int expand_arguments(char *command)
{ {
int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE; int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE;
char * tmpcmd; char * tmpcmd, *cmd, *cmd_copy;
/* We need a clean copy, so strsep can mess up the copy while /* We need a clean copy, so strsep can mess up the copy while
* we write stuff into the original (in a minute) */ * we write stuff into the original (in a minute) */
char * cmd = strdup(command); cmd = cmd_copy = strdup(command);
*command = '\0'; *command = '\0';
for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) { for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) {
if (*tmpcmd == '\0') if (*tmpcmd == '\0')
@ -1006,7 +1006,7 @@ static int expand_arguments(char *command)
globfree (&expand_result); globfree (&expand_result);
} }
} }
free(cmd); free(cmd_copy);
trim(command); trim(command);
} }

View File

@ -970,10 +970,10 @@ static int expand_arguments(char *command)
{ {
int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE; int flags = GLOB_NOCHECK|GLOB_BRACE|GLOB_TILDE;
char * tmpcmd; char * tmpcmd, *cmd, *cmd_copy;
/* We need a clean copy, so strsep can mess up the copy while /* We need a clean copy, so strsep can mess up the copy while
* we write stuff into the original (in a minute) */ * we write stuff into the original (in a minute) */
char * cmd = strdup(command); cmd = cmd_copy = strdup(command);
*command = '\0'; *command = '\0';
for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) { for (tmpcmd = cmd; (tmpcmd = strsep(&cmd, " \t")) != NULL;) {
if (*tmpcmd == '\0') if (*tmpcmd == '\0')
@ -1006,7 +1006,7 @@ static int expand_arguments(char *command)
globfree (&expand_result); globfree (&expand_result);
} }
} }
free(cmd); free(cmd_copy);
trim(command); trim(command);
} }