From bbe866a3819c6a754a5b1d8c5bc5d0701796acfb Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 20 Feb 2023 14:57:31 +0000 Subject: [PATCH] Flood: don't read off the end of some parameter strings This is essentially the same fix as 73c7bc090155ab8c was for Twiddle. The new code is less clever but more correct (and more obviously correct). The bug could be demonstrated by using a parameter string of "c" or "m" with an AddressSanitizer build of Flood. --- flood.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flood.c b/flood.c index 441119c..77eb48a 100644 --- a/flood.c +++ b/flood.c @@ -141,13 +141,13 @@ static void decode_params(game_params *ret, char const *string) if (*string == 'c') { string++; ret->colours = atoi(string); - while (string[1] && isdigit((unsigned char)string[1])) string++; + while (*string && isdigit((unsigned char)*string)) string++; } else if (*string == 'm') { string++; ret->leniency = atoi(string); - while (string[1] && isdigit((unsigned char)string[1])) string++; - } - string++; + while (*string && isdigit((unsigned char)*string)) string++; + } else + string++; } }