Twiddle: don't read off the end of parameter strings ending 'm'

The overrun could be demonstrated by specifying a parameter string of
"3x3m" to a build with AddressSanitizer.
This commit is contained in:
Ben Harris
2023-02-13 14:31:39 +00:00
parent d577aaecab
commit 73c7bc0901

View File

@ -124,13 +124,15 @@ static void decode_params(game_params *ret, char const *string)
while (*string) { while (*string) {
if (*string == 'r') { if (*string == 'r') {
ret->rowsonly = true; ret->rowsonly = true;
string++;
} else if (*string == 'o') { } else if (*string == 'o') {
ret->orientable = true; ret->orientable = true;
string++;
} else if (*string == 'm') { } else if (*string == 'm') {
string++; string++;
ret->movetarget = atoi(string); ret->movetarget = atoi(string);
while (string[1] && isdigit((unsigned char)string[1])) string++; while (*string && isdigit((unsigned char)*string)) string++;
} } else
string++; string++;
} }
} }