From 212d1573c452cddb1b1931890be811f43b4ef09c Mon Sep 17 00:00:00 2001 From: havoc Date: Sat, 11 Sep 2004 15:31:23 +0000 Subject: [PATCH] rewrote Cmd_StuffCmds_f (commandline parser), it now properly handles quoted strings, + and - inside a word, and numbers beginning with + or - git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4474 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 74 +++++++++++++++++++++-------------------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/cmd.c b/cmd.c index 10ee1366..a0747954 100644 --- a/cmd.c +++ b/cmd.c @@ -216,9 +216,9 @@ quake -nosound +cmd amlev1 */ void Cmd_StuffCmds_f (void) { - int i, j; - int s; - char *text, *build, c; + int i, j, l; + // this is per command, and bounds checked (no buffer overflows) + char build[2048]; if (Cmd_Argc () != 1) { @@ -226,56 +226,34 @@ void Cmd_StuffCmds_f (void) return; } -// build the combined string to parse from - s = 0; - for (i=1 ; i '9')) { + l = 0; + j = 1; + while (com_argv[i][j]) + build[l++] = com_argv[i][j++]; i++; - - for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++) - ; - - c = text[j]; - text[j] = 0; - - strcat (build, text+i); - strcat (build, "\n"); - text[j] = c; - i = j-1; + for (;i < com_argc;i++) + { + if (!com_argv[i]) + continue; + if ((com_argv[i][0] == '+' || com_argv[i][0] == '-') && (com_argv[i][1] < '0' || com_argv[i][1] > '9')) + break; + if (l + strlen(com_argv[i]) + 5 > sizeof(build)) + break; + build[l++] = ' '; + build[l++] = '\"'; + for (j = 0;com_argv[i][j];j++) + build[l++] = com_argv[i][j]; + build[l++] = '\"'; + } + build[l++] = '\n'; + build[l++] = 0; + Cbuf_InsertText (build); } } - - if (build[0]) - Cbuf_InsertText (build); - - Mem_Free (text); - Mem_Free (build); } -- 2.39.2