mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Avoid division by zero in Cube grid-size checks
On a triangular grid, Cube allows either d1 or d2 (but not both) to be zero, so it's important to check that each one is not zero before dividing by it. The crash could be triggered by, for instance "cube t0x2".
This commit is contained in:
8
cube.c
8
cube.c
@ -567,9 +567,11 @@ static const char *validate_params(const game_params *params, bool full)
|
|||||||
* can safely multiply them and compare against the
|
* can safely multiply them and compare against the
|
||||||
* _remaining_ space.
|
* _remaining_ space.
|
||||||
*/
|
*/
|
||||||
if ((params->d1 > INT_MAX / params->d1) ||
|
if ((params->d1 > 0 && params->d1 > INT_MAX / params->d1) ||
|
||||||
(params->d2 > (INT_MAX - params->d1*params->d1) / params->d2) ||
|
(params->d2 > 0 &&
|
||||||
(params->d1*params->d2 > (INT_MAX - params->d1*params->d1 -
|
params->d2 > (INT_MAX - params->d1*params->d1) / params->d2) ||
|
||||||
|
(params->d2 > 0 &&
|
||||||
|
params->d1*params->d2 > (INT_MAX - params->d1*params->d1 -
|
||||||
params->d2*params->d2) / params->d2))
|
params->d2*params->d2) / params->d2))
|
||||||
return "Grid area must not be unreasonably large";
|
return "Grid area must not be unreasonably large";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user