]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cmd.c
fix cmd again (fix by Blub and me)
[xonotic/darkplaces.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index 3a269baa50e9f2afbd5caa517cafc1e341782df6..b515dbb92d6cd747424a141ee21b15b8c2689f41 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // maximum number of parameters to a command
 #define        MAX_ARGS 80
 // maximum tokenizable commandline length (counting NUL terminations)
-#define CMD_TOKENIZELENGTH (MAX_INPUTLINE + 80)
+#define CMD_TOKENIZELENGTH (MAX_INPUTLINE + MAX_ARGS)
 
 typedef struct cmdalias_s
 {
@@ -161,7 +161,9 @@ void Cbuf_Execute (void)
                {
                        if (text[i] == '"')
                                quotes ^= 1;
-                       if (text[i] == '\\' && (text[i+1] == '"' || text[i+1] == '\\'))
+                       // make sure i doesn't get > cursize which causes a negative
+                       // size in memmove, which is fatal --blub
+                       if (i < (cmd_text.cursize-1) && (text[i] == '\\' && (text[i+1] == '"' || text[i+1] == '\\')))
                                i++;
                        if ( !quotes &&  text[i] == ';')
                                break;  // don't break if inside a quoted string
@@ -169,8 +171,17 @@ void Cbuf_Execute (void)
                                break;
                }
 
-               memcpy (line, text, i);
-               line[i] = 0;
+               // better than CRASHING on overlong input lines that may SOMEHOW enter the buffer
+               if(i >= MAX_INPUTLINE)
+               {
+                       Con_Printf("Warning: console input buffer had an overlong line. Ignored.\n");
+                       line[0] = 0;
+               }
+               else
+               {
+                       memcpy (line, text, i);
+                       line[i] = 0;
+               }
 
 // delete the text from the command buffer and move remaining commands down
 // this is necessary because commands (exec, alias) can insert data at the
@@ -306,7 +317,7 @@ static void Cmd_Exec_f (void)
                Con_Printf("couldn't exec %s\n",Cmd_Argv(1));
                return;
        }
-       Con_DPrintf("execing %s\n",Cmd_Argv(1));
+       Con_Printf("execing %s\n",Cmd_Argv(1));
 
        // if executing default.cfg for the first time, lock the cvar defaults
        // it may seem backwards to insert this text BEFORE the default.cfg
@@ -413,7 +424,7 @@ static void Cmd_Toggle_f(void)
                }
                else
                { // Invalid CVar
-                       Con_Printf("ERROR : CVar '%s' not found\n", Cmd_Argv(2) );
+                       Con_Printf("ERROR : CVar '%s' not found\n", Cmd_Argv(1) );
                }
        }
 }
@@ -824,12 +835,12 @@ Called for aliases and fills in the alias into the cbuffer
 */
 static void Cmd_ExecuteAlias (cmdalias_t *alias)
 {
-       static char buffer[ MAX_INPUTLINE + 2 ];
-       static char buffer2[ MAX_INPUTLINE * 2 + 2 ];
+       static char buffer[ MAX_INPUTLINE ];
+       static char buffer2[ MAX_INPUTLINE ];
        Cmd_PreprocessString( alias->value, buffer, sizeof(buffer) - 2, alias );
        // insert at start of command buffer, so that aliases execute in order
        // (fixes bug introduced by Black on 20050705)
-       
+
        // Note: Cbuf_PreprocessString will be called on this string AGAIN! So we
        // have to make sure that no second variable expansion takes place, otherwise
        // alias parameters containing dollar signs can have bad effects.