aboutsummaryrefslogtreecommitdiff
path: root/flip.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-10 11:07:14 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commit26d0633f87ccdbaf7035e2e14d9dfbfd7f379527 (patch)
tree6f4d99c72e26acee0dedf5c988799388f2cb76de /flip.c
parent522588f699b3c910c5a47f8b8185e69250665313 (diff)
downloadpuzzles-26d0633f87ccdbaf7035e2e14d9dfbfd7f379527.zip
puzzles-26d0633f87ccdbaf7035e2e14d9dfbfd7f379527.tar.gz
puzzles-26d0633f87ccdbaf7035e2e14d9dfbfd7f379527.tar.bz2
puzzles-26d0633f87ccdbaf7035e2e14d9dfbfd7f379527.tar.xz
Last-ditch maximum size limit for Flip
This makes sure that width * height <= INT_MAX, which it rather needs to be. Also in Flip's case that the square of the area still fits in an int.
Diffstat (limited to 'flip.c')
-rw-r--r--flip.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/flip.c b/flip.c
index e6ff0a2..9486f19 100644
--- a/flip.c
+++ b/flip.c
@@ -8,6 +8,7 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
+#include <limits.h>
#include <math.h>
#include "puzzles.h"
@@ -181,9 +182,16 @@ static game_params *custom_params(const config_item *cfg)
static const char *validate_params(const game_params *params, bool full)
{
+ int wh;
+
if (params->w <= 0 || params->h <= 0)
return "Width and height must both be greater than zero";
- return NULL;
+ if (params->w > (INT_MAX - 3) / params->h)
+ return "Width times height must not be unreasonably large";
+ wh = params->w * params->h;
+ if (wh > (INT_MAX - 3) / wh)
+ return "Width times height is too large";
+ return NULL;
}
static char *encode_bitmap(unsigned char *bmp, int len)