aboutsummaryrefslogtreecommitdiff
path: root/filling.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-08 09:57:53 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commit8a06ff26fc6abd77a4b4a08b839943f588d92dcf (patch)
treef2187175930c75e8aba3a41c67f60b03d41ea00f /filling.c
parenta45f1830cf4af0fbaf2fad448f717a6458b48b24 (diff)
downloadpuzzles-8a06ff26fc6abd77a4b4a08b839943f588d92dcf.zip
puzzles-8a06ff26fc6abd77a4b4a08b839943f588d92dcf.tar.gz
puzzles-8a06ff26fc6abd77a4b4a08b839943f588d92dcf.tar.bz2
puzzles-8a06ff26fc6abd77a4b4a08b839943f588d92dcf.tar.xz
Filling: validate length of auto-solve move strings
Without this, execute_move() can end up reading off the end of the move string, which isn't very friendly. Also remove the comment saying that the move string doesn't have to be null-terminated, because now it does.
Diffstat (limited to 'filling.c')
-rw-r--r--filling.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/filling.c b/filling.c
index c07157e..92939a1 100644
--- a/filling.c
+++ b/filling.c
@@ -1110,8 +1110,6 @@ static bool solver(const int *orig, int w, int h, char **solution) {
**solution = 's';
for (i = 0; i < sz; ++i) (*solution)[i + 1] = ss.board[i] + '0';
(*solution)[sz + 1] = '\0';
- /* We don't need the \0 for execute_move (the only user)
- * I'm just being printf-friendly in case I wanna print */
}
sfree(ss.dsf);
@@ -1589,6 +1587,7 @@ static game_state *execute_move(const game_state *state, const char *move)
if (*move == 's') {
int i = 0;
+ if (strlen(move) != sz + 1) return NULL;
new_state = dup_game(state);
for (++move; i < sz; ++i) new_state->board[i] = move[i] - '0';
new_state->cheated = true;