aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-01-10 20:53:07 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-01-15 16:24:27 +0000
commitd422dd6009f3e48e13d5f7f162813537902e125c (patch)
treeb3f5c5f0f91f17196e6fe3aaa666d4c8375d36db
parentb3f3345764b0808a7a97b9c3a2a1888fd62383a0 (diff)
downloadpuzzles-d422dd6009f3e48e13d5f7f162813537902e125c.zip
puzzles-d422dd6009f3e48e13d5f7f162813537902e125c.tar.gz
puzzles-d422dd6009f3e48e13d5f7f162813537902e125c.tar.bz2
puzzles-d422dd6009f3e48e13d5f7f162813537902e125c.tar.xz
Last-ditch grid-size limit for Galaxies
At least prevent integer overflow when constructing the grid.
-rw-r--r--galaxies.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/galaxies.c b/galaxies.c
index 36845d4..c367b29 100644
--- a/galaxies.c
+++ b/galaxies.c
@@ -42,6 +42,7 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
+#include <limits.h>
#include <math.h>
#include "puzzles.h"
@@ -282,6 +283,10 @@ static const char *validate_params(const game_params *params, bool full)
{
if (params->w < 3 || params->h < 3)
return "Width and height must both be at least 3";
+ if (params->w > INT_MAX / 2 || params->h > INT_MAX / 2 ||
+ params->w > (INT_MAX - params->w*2 - params->h*2 - 1) / 4 / params->h)
+ return "Width times height must not be unreasonably large";
+
/*
* This shouldn't be able to happen at all, since decode_params
* and custom_params will never generate anything that isn't