aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-11 00:03:57 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commitb3f3345764b0808a7a97b9c3a2a1888fd62383a0 (patch)
tree73629a43a36fd670f2ef3e00edd2ae1f86531a21
parent97484b098f33266f6c747c292c708281cb15a286 (diff)
downloadpuzzles-b3f3345764b0808a7a97b9c3a2a1888fd62383a0.zip
puzzles-b3f3345764b0808a7a97b9c3a2a1888fd62383a0.tar.gz
puzzles-b3f3345764b0808a7a97b9c3a2a1888fd62383a0.tar.bz2
puzzles-b3f3345764b0808a7a97b9c3a2a1888fd62383a0.tar.xz
Last-ditch grid-size limit for Dominosa
At least prevent integer overflow when constructing the grid.
-rw-r--r--dominosa.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/dominosa.c b/dominosa.c
index 0be1c68..25f2a0b 100644
--- a/dominosa.c
+++ b/dominosa.c
@@ -47,6 +47,7 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
+#include <limits.h>
#include <math.h>
#include "puzzles.h"
@@ -243,6 +244,10 @@ static const char *validate_params(const game_params *params, bool full)
{
if (params->n < 1)
return "Maximum face number must be at least one";
+ if (params->n > INT_MAX - 2 ||
+ params->n + 2 > INT_MAX / (params->n + 1))
+ return "Maximum face number must not be unreasonably large";
+
if (params->diff >= DIFFCOUNT)
return "Unknown difficulty rating";
return NULL;