mirror of
https://github.com/ioquake/ioq3.git
synced 2025-02-23 12:01:11 +00:00
* Move storage of console history from a cvar to a file in order to alleviate
security concerns
This commit is contained in:
parent
f9bb47d9af
commit
fb58d8f123
1 changed files with 74 additions and 47 deletions
|
@ -1372,8 +1372,10 @@ void Key_ClearStates (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must not exceed MAX_CMD_LINE
|
// This must not exceed MAX_CMD_LINE
|
||||||
#define MAX_CONSOLE_SAVE_BUFFER 1024
|
#define MAX_CONSOLE_SAVE_BUFFER 1024
|
||||||
static char consoleSaveBuffer[ MAX_CONSOLE_SAVE_BUFFER ];
|
#define CONSOLE_HISTORY_FILE "q3history"
|
||||||
|
static char consoleSaveBuffer[ MAX_CONSOLE_SAVE_BUFFER ];
|
||||||
|
static int consoleSaveBufferSize = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================
|
================
|
||||||
|
@ -1384,51 +1386,63 @@ Load the console history from cl_consoleHistory
|
||||||
*/
|
*/
|
||||||
void CL_LoadConsoleHistory( void )
|
void CL_LoadConsoleHistory( void )
|
||||||
{
|
{
|
||||||
char *token, *text_p;
|
char *token, *text_p;
|
||||||
int i, numChars, numLines = 0;
|
int i, numChars, numLines = 0;
|
||||||
cvar_t *cv;
|
fileHandle_t f;
|
||||||
|
|
||||||
cv = Cvar_Get( "cl_consoleHistory", "", CVAR_ARCHIVE|CVAR_ROM );
|
consoleSaveBufferSize = FS_FOpenFileRead( CONSOLE_HISTORY_FILE, &f, qfalse );
|
||||||
Q_strncpyz( consoleSaveBuffer, cv->string, MAX_CONSOLE_SAVE_BUFFER );
|
if( !f )
|
||||||
|
|
||||||
text_p = consoleSaveBuffer;
|
|
||||||
|
|
||||||
for( i = COMMAND_HISTORY - 1; i >= 0; i-- )
|
|
||||||
{
|
{
|
||||||
if( !*( token = COM_Parse( &text_p ) ) )
|
Com_Printf( "Couldn't read %s.\n", CONSOLE_HISTORY_FILE );
|
||||||
break;
|
return;
|
||||||
|
|
||||||
historyEditLines[ i ].cursor = atoi( token );
|
|
||||||
|
|
||||||
if( !*( token = COM_Parse( &text_p ) ) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
historyEditLines[ i ].scroll = atoi( token );
|
|
||||||
|
|
||||||
if( !*( token = COM_Parse( &text_p ) ) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
numChars = atoi( token );
|
|
||||||
text_p++;
|
|
||||||
if( numChars > ( strlen( consoleSaveBuffer ) - ( text_p - consoleSaveBuffer ) ) )
|
|
||||||
{
|
|
||||||
Com_DPrintf( S_COLOR_YELLOW "WARNING: probable corrupt history\n" );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Com_Memcpy( historyEditLines[ i ].buffer,
|
|
||||||
text_p, numChars );
|
|
||||||
historyEditLines[ i ].buffer[ numChars ] = '\0';
|
|
||||||
text_p += numChars;
|
|
||||||
|
|
||||||
numLines++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove( &historyEditLines[ 0 ], &historyEditLines[ i + 1 ],
|
if( consoleSaveBufferSize <= MAX_CONSOLE_SAVE_BUFFER &&
|
||||||
numLines * sizeof( field_t ) );
|
FS_Read( consoleSaveBuffer, consoleSaveBufferSize, f ) == consoleSaveBufferSize )
|
||||||
for( i = numLines; i < COMMAND_HISTORY; i++ )
|
{
|
||||||
Field_Clear( &historyEditLines[ i ] );
|
text_p = consoleSaveBuffer;
|
||||||
|
|
||||||
historyLine = nextHistoryLine = numLines;
|
for( i = COMMAND_HISTORY - 1; i >= 0; i-- )
|
||||||
|
{
|
||||||
|
if( !*( token = COM_Parse( &text_p ) ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
historyEditLines[ i ].cursor = atoi( token );
|
||||||
|
|
||||||
|
if( !*( token = COM_Parse( &text_p ) ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
historyEditLines[ i ].scroll = atoi( token );
|
||||||
|
|
||||||
|
if( !*( token = COM_Parse( &text_p ) ) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
numChars = atoi( token );
|
||||||
|
text_p++;
|
||||||
|
if( numChars > ( strlen( consoleSaveBuffer ) - ( text_p - consoleSaveBuffer ) ) )
|
||||||
|
{
|
||||||
|
Com_DPrintf( S_COLOR_YELLOW "WARNING: probable corrupt history\n" );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Com_Memcpy( historyEditLines[ i ].buffer,
|
||||||
|
text_p, numChars );
|
||||||
|
historyEditLines[ i ].buffer[ numChars ] = '\0';
|
||||||
|
text_p += numChars;
|
||||||
|
|
||||||
|
numLines++;
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove( &historyEditLines[ 0 ], &historyEditLines[ i + 1 ],
|
||||||
|
numLines * sizeof( field_t ) );
|
||||||
|
for( i = numLines; i < COMMAND_HISTORY; i++ )
|
||||||
|
Field_Clear( &historyEditLines[ i ] );
|
||||||
|
|
||||||
|
historyLine = nextHistoryLine = numLines;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Com_Printf( "Couldn't read %s.\n", CONSOLE_HISTORY_FILE );
|
||||||
|
|
||||||
|
FS_FCloseFile( f );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1441,8 +1455,9 @@ so that it persists across invocations of q3
|
||||||
*/
|
*/
|
||||||
void CL_SaveConsoleHistory( void )
|
void CL_SaveConsoleHistory( void )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int lineLength, saveBufferLength, additionalLength;
|
int lineLength, saveBufferLength, additionalLength;
|
||||||
|
fileHandle_t f;
|
||||||
|
|
||||||
consoleSaveBuffer[ 0 ] = '\0';
|
consoleSaveBuffer[ 0 ] = '\0';
|
||||||
|
|
||||||
|
@ -1454,8 +1469,8 @@ void CL_SaveConsoleHistory( void )
|
||||||
lineLength = strlen( historyEditLines[ i ].buffer );
|
lineLength = strlen( historyEditLines[ i ].buffer );
|
||||||
saveBufferLength = strlen( consoleSaveBuffer );
|
saveBufferLength = strlen( consoleSaveBuffer );
|
||||||
|
|
||||||
//ICK "seta cl_consoleHistory " + "%d %d %d " = 23 + 13 = 36
|
//ICK
|
||||||
additionalLength = lineLength + 36;
|
additionalLength = lineLength + strlen( "999 999 999 " );
|
||||||
|
|
||||||
if( saveBufferLength + additionalLength < MAX_CONSOLE_SAVE_BUFFER )
|
if( saveBufferLength + additionalLength < MAX_CONSOLE_SAVE_BUFFER )
|
||||||
{
|
{
|
||||||
|
@ -1473,5 +1488,17 @@ void CL_SaveConsoleHistory( void )
|
||||||
}
|
}
|
||||||
while( i != ( nextHistoryLine - 1 ) % COMMAND_HISTORY );
|
while( i != ( nextHistoryLine - 1 ) % COMMAND_HISTORY );
|
||||||
|
|
||||||
Cvar_Set( "cl_consoleHistory", consoleSaveBuffer );
|
consoleSaveBufferSize = strlen( consoleSaveBuffer );
|
||||||
|
|
||||||
|
f = FS_FOpenFileWrite( CONSOLE_HISTORY_FILE );
|
||||||
|
if( !f )
|
||||||
|
{
|
||||||
|
Com_Printf( "Couldn't write %s.\n", CONSOLE_HISTORY_FILE );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( FS_Write( consoleSaveBuffer, consoleSaveBufferSize, f ) < consoleSaveBufferSize )
|
||||||
|
Com_Printf( "Couldn't write %s.\n", CONSOLE_HISTORY_FILE );
|
||||||
|
|
||||||
|
FS_FCloseFile( f );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue