From 02aca4a7d7478be517fe5f7d32ace2512bc08e6b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 8 Feb 2021 11:37:49 +0000 Subject: [PATCH] Don't run off the end of a string. Fixes https://gitlab.com/kicad/code/kicad/issues/7461 --- common/common.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index f586760fad..ec74204a2a 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -169,8 +169,16 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject ) size_t m = n + 1; wxUniChar str_m = str[m]; - while( m < strlen && ( wxIsalnum( str_m ) || str_m == wxT( '_' ) || str_m == wxT( ':' ) ) ) - str_m = str[++m]; + while( wxIsalnum( str_m ) || str_m == wxT( '_' ) || str_m == wxT( ':' ) ) + { + if( ++m == strlen ) + { + str_m = 0; + break; + } + + str_m = str[m]; + } wxString strVarName( str.c_str() + n + 1, m - n - 1 );