mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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.
This commit is contained in:
2
mines.c
2
mines.c
@ -2006,6 +2006,8 @@ static const char *validate_desc(const game_params *params, const char *desc)
|
|||||||
desc++;
|
desc++;
|
||||||
if (!*desc || !isdigit((unsigned char)*desc))
|
if (!*desc || !isdigit((unsigned char)*desc))
|
||||||
return "No initial mine count in game description";
|
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))
|
while (*desc && isdigit((unsigned char)*desc))
|
||||||
desc++; /* skip over mine count */
|
desc++; /* skip over mine count */
|
||||||
if (*desc != ',')
|
if (*desc != ',')
|
||||||
|
Reference in New Issue
Block a user