ref: e616d7aac9fff2d65bde4c6f8dcfc8d1222dc803
parent: 68f9fae973e2ffb6c0b9ed1e0761d3a0768455ad
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sat Jan 7 15:33:42 EST 2023
Mosaic: fault out-of-bounds moves in execute_move() Returning NULL in this case is better than dereferencing it.
--- a/mosaic.c
+++ b/mosaic.c
@@ -1297,6 +1297,10 @@
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 @@
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),