Add more bounds checking in KIwxExpandEnvVars

Fixes https://gitlab.com/kicad/code/kicad/-/issues/7461
This commit is contained in:
Roberto Fernandez Bautista 2021-03-16 22:14:47 +00:00 committed by Jeff Young
parent 6c29f54988
commit 35438d3533
1 changed files with 5 additions and 1 deletions

View File

@ -167,6 +167,10 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject )
}
size_t m = n + 1;
if( m >= strlen )
break;
wxUniChar str_m = str[m];
while( wxIsalnum( str_m ) || str_m == wxT( '_' ) || str_m == wxT( ':' ) )
@ -243,7 +247,7 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject )
case wxT( '\\' ):
// backslash can be used to suppress special meaning of % and $
if( n != strlen - 1 && (str[n + 1] == wxT( '%' ) || str[n + 1] == wxT( '$' )) )
if( n < strlen - 1 && (str[n + 1] == wxT( '%' ) || str[n + 1] == wxT( '$' )) )
{
str_n = str[++n];
strResult += str_n;