From 28671e76b736aeb860b1f725898c45fe70ae6212 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 28 Jan 2023 19:34:28 +0000 Subject: [PATCH] Don't segfault on premature solve moves in Mines If a save file contained a solve move as the first move, Mines would dereference a null pointer trying to look up the (at that point undetermined) mine locations. Now execute_move() politely returns NULL instead. This save file demonstrates the problem: SAVEFILE:41:Simon Tatham's Portable Puzzle Collection VERSION :1:1 GAME :5:Mines PARAMS :5:3x3n0 CPARAMS :5:3x3n0 DESC :127:r0,u,7a142789cabddc3fc4dcb7d2baa4a4937b33c9613ea870ac098e217981ad339930af585557d62048ea745d05b01475d9699596b394cc0adeebf0440a02 UI :2:D0 TIME :1:0 NSTATES :1:2 STATEPOS:1:2 SOLVE :1:S --- mines.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mines.c b/mines.c index 8af7c20..325c850 100644 --- a/mines.c +++ b/mines.c @@ -2637,6 +2637,7 @@ static game_state *execute_move(const game_state *from, const char *move) if (!strcmp(move, "S")) { int yy, xx; + if (!from->layout->mines) return NULL; /* Game not started. */ ret = dup_game(from); if (!ret->dead) { /*