mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
fix a buffer overflow snax found
This commit is contained in:
parent
864e765293
commit
119731e90e
1 changed files with 16 additions and 6 deletions
|
@ -146,12 +146,14 @@ Cbuf_InsertText (const char *text)
|
||||||
cmd_text.data[textlen] = '\n';
|
cmd_text.data[textlen] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static const char *
|
||||||
extract_line (char *line)
|
extract_line (void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *text;
|
char *text;
|
||||||
int quotes;
|
int quotes;
|
||||||
|
static char *line;
|
||||||
|
static int line_size;
|
||||||
|
|
||||||
// find a \n or ; line break
|
// find a \n or ; line break
|
||||||
text = (char *) cmd_text.data;
|
text = (char *) cmd_text.data;
|
||||||
|
@ -166,6 +168,13 @@ extract_line (char *line)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (i + 1 > line_size) {
|
||||||
|
line_size = ((i + 1) + 1023) & ~1023;
|
||||||
|
line = realloc (line, line_size);
|
||||||
|
if (!line)
|
||||||
|
Sys_Error ("extract_line: memory alloc failur");
|
||||||
|
}
|
||||||
|
|
||||||
memcpy (line, text, i);
|
memcpy (line, text, i);
|
||||||
line[i] = '\0';
|
line[i] = '\0';
|
||||||
// delete the text from the command buffer and move remaining commands
|
// delete the text from the command buffer and move remaining commands
|
||||||
|
@ -179,15 +188,16 @@ extract_line (char *line)
|
||||||
cmd_text.cursize -= i;
|
cmd_text.cursize -= i;
|
||||||
memcpy (text, text + i, cmd_text.cursize);
|
memcpy (text, text + i, cmd_text.cursize);
|
||||||
}
|
}
|
||||||
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cbuf_Execute (void)
|
Cbuf_Execute (void)
|
||||||
{
|
{
|
||||||
char line[1024];
|
const char *line;
|
||||||
|
|
||||||
while (cmd_text.cursize) {
|
while (cmd_text.cursize) {
|
||||||
extract_line (line);
|
line = extract_line ();
|
||||||
// execute the command line
|
// execute the command line
|
||||||
// Sys_DPrintf("+%s\n",line),
|
// Sys_DPrintf("+%s\n",line),
|
||||||
Cmd_ExecuteString (line, src_command);
|
Cmd_ExecuteString (line, src_command);
|
||||||
|
@ -204,10 +214,10 @@ Cbuf_Execute (void)
|
||||||
void
|
void
|
||||||
Cbuf_Execute_Sets (void)
|
Cbuf_Execute_Sets (void)
|
||||||
{
|
{
|
||||||
char line[1024];
|
const char *line;
|
||||||
|
|
||||||
while (cmd_text.cursize) {
|
while (cmd_text.cursize) {
|
||||||
extract_line (line);
|
line = extract_line ();
|
||||||
// execute the command line
|
// execute the command line
|
||||||
if (strnequal (line, "set", 3) && isspace ((int) line[3])) {
|
if (strnequal (line, "set", 3) && isspace ((int) line[3])) {
|
||||||
// Sys_DPrintf ("+%s\n",line);
|
// Sys_DPrintf ("+%s\n",line);
|
||||||
|
|
Loading…
Reference in a new issue