From: divverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Sun, 16 Mar 2008 17:31:32 +0000 (+0000)
Subject: fix cmd again (fix by Blub and me)
X-Git-Tag: xonotic-v0.1.0preview~2314
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=19a0060d874682443467614070a3a03e0d5f890f;p=xonotic%2Fdarkplaces.git

fix cmd again (fix by Blub and me)


git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8212 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/cmd.c b/cmd.c
index 4e1fb729..b515dbb9 100644
--- a/cmd.c
+++ b/cmd.c
@@ -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,13 +171,17 @@ void Cbuf_Execute (void)
 				break;
 		}
 
-		/* should never happen
+		// better than CRASHING on overlong input lines that may SOMEHOW enter the buffer
 		if(i >= MAX_INPUTLINE)
-			i = MAX_INPUTLINE - 1;
-		*/
-
-		memcpy (line, text, i);
-		line[i] = 0;
+		{
+			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