Fix a buffer overflow in Cmd_Alias_f caused by weird quoting. Not sure if

the resulting alias will work as expected wrt id's command parsing, but
that's another issue :)
This commit is contained in:
Bill Currie 2005-03-28 04:35:22 +00:00
parent f34dc8f884
commit 76649e674e

View file

@ -332,7 +332,7 @@ static void
Cmd_Alias_f (void) Cmd_Alias_f (void)
{ {
cmdalias_t *alias; cmdalias_t *alias;
char *cmd; dstring_t *cmd;
int i, c; int i, c;
const char *s; const char *s;
@ -371,17 +371,17 @@ Cmd_Alias_f (void)
return; return;
} }
// copy the rest of the command line // copy the rest of the command line
cmd = malloc (strlen (Cmd_Args (1)) + 2); // can never be longer puts (Cmd_Args(1));
SYS_CHECKMEM (cmd); cmd = dstring_newstr ();
cmd[0] = 0; // start out with a null string
c = Cmd_Argc (); c = Cmd_Argc ();
for (i = 2; i < c; i++) { for (i = 2; i < c; i++) {
strcat (cmd, Cmd_Argv (i)); dstring_appendstr (cmd, Cmd_Argv (i));
if (i != c - 1) if (i != c - 1)
strcat (cmd, " "); dstring_appendstr (cmd, " ");
} }
puts (cmd->str);
alias->value = cmd; alias->value = dstring_freeze (cmd);
} }
static void static void