aboutsummaryrefslogtreecommitdiff
path: root/mines.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-28 23:12:52 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-28 23:12:52 +0000
commit75e8a1a9cabe7567f6019b1226783b61ba1ac42f (patch)
tree64135b6d90b9895937b45a914c761e0d31266304 /mines.c
parent28671e76b736aeb860b1f725898c45fe70ae6212 (diff)
downloadpuzzles-75e8a1a9cabe7567f6019b1226783b61ba1ac42f.zip
puzzles-75e8a1a9cabe7567f6019b1226783b61ba1ac42f.tar.gz
puzzles-75e8a1a9cabe7567f6019b1226783b61ba1ac42f.tar.bz2
puzzles-75e8a1a9cabe7567f6019b1226783b61ba1ac42f.tar.xz
Limit number of mines in Mines game description
Without this, it's possible to specify a description that has more mines than there are places on the board to place them, which eventually leads to a division by zero. This can be demonstrated by entering a game description of "3:r8,u," and then clicking anywhere on the board.
Diffstat (limited to 'mines.c')
-rw-r--r--mines.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/mines.c b/mines.c
index 325c850..5674849 100644
--- a/mines.c
+++ b/mines.c
@@ -2006,6 +2006,8 @@ static const char *validate_desc(const game_params *params, const char *desc)
desc++;
if (!*desc || !isdigit((unsigned char)*desc))
return "No initial mine count in game description";
+ if (atoi(desc) > wh - 9)
+ return "Too many mines for grid size";
while (*desc && isdigit((unsigned char)*desc))
desc++; /* skip over mine count */
if (*desc != ',')