aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-07 20:33:42 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commite616d7aac9fff2d65bde4c6f8dcfc8d1222dc803 (patch)
tree0bd1a3218c42b4751773b16b2044e04b2f203987
parent68f9fae973e2ffb6c0b9ed1e0761d3a0768455ad (diff)
downloadpuzzles-e616d7aac9fff2d65bde4c6f8dcfc8d1222dc803.zip
puzzles-e616d7aac9fff2d65bde4c6f8dcfc8d1222dc803.tar.gz
puzzles-e616d7aac9fff2d65bde4c6f8dcfc8d1222dc803.tar.bz2
puzzles-e616d7aac9fff2d65bde4c6f8dcfc8d1222dc803.tar.xz
Mosaic: fault out-of-bounds moves in execute_move()
Returning NULL in this case is better than dereferencing it.
-rw-r--r--mosaic.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/mosaic.c b/mosaic.c
index 84ea1f3..3ccd10d 100644
--- a/mosaic.c
+++ b/mosaic.c
@@ -1297,6 +1297,10 @@ static game_state *execute_move(const game_state *state, const char *move)
return new_state;
}
cell = get_coords(new_state, new_state->cells_contents, x, y);
+ if (cell == NULL) {
+ sfree(new_state);
+ return NULL;
+ }
if (*cell >= STATE_OK_NUM) {
*cell &= STATE_OK_NUM;
}
@@ -1363,6 +1367,10 @@ static game_state *execute_move(const game_state *state, const char *move)
for (i = 0; i < diff; i++) {
cell = get_coords(new_state, new_state->cells_contents,
x + (dirX * i), y + (dirY * i));
+ if (cell == NULL) {
+ sfree(new_state);
+ return NULL;
+ }
if ((*cell & STATE_OK_NUM) == 0) {
*cell = last_state;
update_board_state_around(new_state, x + (dirX * i),