@@ -1302,7 +1302,7 @@ void CHudCloseCaption::Reset( void )
13021302 Unlock ();
13031303}
13041304
1305- bool CHudCloseCaption::SplitCommand ( wchar_t const **ppIn, wchar_t *cmd, wchar_t *args ) const
1305+ bool CHudCloseCaption::SplitCommand ( wchar_t const **ppIn, wchar_t *cmd, wchar_t *args, int size ) const
13061306{
13071307 const wchar_t *in = *ppIn;
13081308 const wchar_t *oldin = in;
@@ -1317,8 +1317,11 @@ bool CHudCloseCaption::SplitCommand( wchar_t const **ppIn, wchar_t *cmd, wchar_t
13171317 cmd[ 0 ]= 0 ;
13181318 wchar_t *out = cmd;
13191319 in++;
1320- while ( *in != L' \0 ' && *in != L' :' && *in != L' >' && !isspace ( *in ) )
1320+ while ( *in != L' \0 ' && *in != L' :' && *in != L' >' && !V_isspace ( *in ) )
13211321 {
1322+ if ( (int )( out - cmd ) + (int )sizeof ( wchar_t ) >= size )
1323+ break ;
1324+
13221325 *out++ = *in++;
13231326 }
13241327 *out = L' \0 ' ;
@@ -1333,6 +1336,9 @@ bool CHudCloseCaption::SplitCommand( wchar_t const **ppIn, wchar_t *cmd, wchar_t
13331336 out = args;
13341337 while ( *in != L' \0 ' && *in != L' >' )
13351338 {
1339+ if ( (int )( out - args ) + (int )sizeof ( wchar_t ) >= size )
1340+ break ;
1341+
13361342 *out++ = *in++;
13371343 }
13381344 *out = L' \0 ' ;
@@ -1360,7 +1366,7 @@ bool CHudCloseCaption::GetFloatCommandValue( const wchar_t *stream, const wchar_
13601366 wchar_t cmd[ 256 ];
13611367 wchar_t args[ 256 ];
13621368
1363- if ( SplitCommand ( &curpos, cmd, args ) )
1369+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
13641370 {
13651371 if ( !wcscmp ( cmd, findcmd ) )
13661372 {
@@ -1384,7 +1390,7 @@ bool CHudCloseCaption::StreamHasCommand( const wchar_t *stream, const wchar_t *f
13841390 wchar_t cmd[ 256 ];
13851391 wchar_t args[ 256 ];
13861392
1387- if ( SplitCommand ( &curpos, cmd, args ) )
1393+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
13881394 {
13891395 if ( !wcscmp ( cmd, findcmd ) )
13901396 {
@@ -1423,7 +1429,7 @@ bool CHudCloseCaption::StreamHasCommand( const wchar_t *stream, const wchar_t *s
14231429 wchar_t cmd[ 256 ];
14241430 wchar_t args[ 256 ];
14251431
1426- if ( SplitCommand ( &curpos, cmd, args ) )
1432+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
14271433 {
14281434 if ( !wcscmp ( cmd, search ) )
14291435 {
@@ -1515,7 +1521,7 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
15151521
15161522 const wchar_t *prevpos = curpos;
15171523
1518- if ( SplitCommand ( &curpos, cmd, args ) )
1524+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
15191525 {
15201526 if ( !wcscmp ( cmd, L" delay" ) )
15211527 {
@@ -1722,7 +1728,7 @@ void CHudCloseCaption::ComputeStreamWork( int available_width, CCloseCaptionItem
17221728 wchar_t cmd[ 256 ];
17231729 wchar_t args[ 256 ];
17241730
1725- if ( SplitCommand ( &curpos, cmd, args ) )
1731+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
17261732 {
17271733 if ( !wcscmp ( cmd, L" cr" ) )
17281734 {
@@ -1976,7 +1982,7 @@ bool CHudCloseCaption::GetNoRepeatValue( const wchar_t *caption, float &retval )
19761982 wchar_t cmd[ 256 ];
19771983 wchar_t args[ 256 ];
19781984
1979- if ( SplitCommand ( &curpos, cmd, args ) )
1985+ if ( SplitCommand ( &curpos, cmd, args, sizeof ( cmd ) ) )
19801986 {
19811987 if ( !wcscmp ( cmd, L" norepeat" ) )
19821988 {
0 commit comments