mirror of
https://github.com/UberGames/ioef.git
synced 2024-11-28 06:52:35 +00:00
Simulate line buffering and fix the overflow bug in Com_ReadFromPipe(), patch from DevHC.
This commit is contained in:
parent
b9a060bfe2
commit
5d24905c8d
1 changed files with 35 additions and 5 deletions
|
@ -2883,15 +2883,45 @@ Read whatever is in com_pipefile, if anything, and execute it
|
||||||
*/
|
*/
|
||||||
void Com_ReadFromPipe( void )
|
void Com_ReadFromPipe( void )
|
||||||
{
|
{
|
||||||
char buffer[MAX_STRING_CHARS] = {""};
|
static char buf[MAX_STRING_CHARS];
|
||||||
qboolean read;
|
static int accu = 0;
|
||||||
|
int read;
|
||||||
|
|
||||||
if( !pipefile )
|
if( !pipefile )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
read = FS_Read( buffer, sizeof( buffer ), pipefile );
|
while( ( read = FS_Read( buf + accu, sizeof( buf ) - accu - 1, pipefile ) ) > 0 )
|
||||||
if( read )
|
{
|
||||||
Cbuf_ExecuteText( EXEC_APPEND, buffer );
|
char *brk = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for( i = accu; i < accu + read; ++i )
|
||||||
|
{
|
||||||
|
if( buf[ i ] == '\0' )
|
||||||
|
buf[ i ] = '\n';
|
||||||
|
if( buf[ i ] == '\n' || buf[ i ] == '\r' )
|
||||||
|
brk = &buf[ i + 1 ];
|
||||||
|
}
|
||||||
|
buf[ accu + read ] = '\0';
|
||||||
|
|
||||||
|
accu += read;
|
||||||
|
|
||||||
|
if( brk )
|
||||||
|
{
|
||||||
|
char tmp = *brk;
|
||||||
|
*brk = '\0';
|
||||||
|
Cbuf_ExecuteText( EXEC_APPEND, buf );
|
||||||
|
*brk = tmp;
|
||||||
|
|
||||||
|
accu -= brk - buf;
|
||||||
|
memmove( buf, brk, accu + 1 );
|
||||||
|
}
|
||||||
|
else if( accu >= sizeof( buf ) - 1 ) // full
|
||||||
|
{
|
||||||
|
Cbuf_ExecuteText( EXEC_APPEND, buf );
|
||||||
|
accu = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue