From 91c0fac1dc98be2ecc074d83368df74f9f755641 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 10 Jan 2023 00:28:09 +0000 Subject: [PATCH] Last-ditch maximum size limit for Palisade This makes sure that width * height <= INT_MAX, which it rather needs to be. --- palisade.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/palisade.c b/palisade.c index 4096d12..865cfd8 100644 --- a/palisade.c +++ b/palisade.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -156,13 +157,15 @@ static game_params *custom_params(const config_item *cfg) static const char *validate_params(const game_params *params, bool full) { - int w = params->w, h = params->h, k = params->k, wh = w * h; + int w = params->w, h = params->h, k = params->k, wh; if (k < 1) return "Region size must be at least one"; if (w < 1) return "Width must be at least one"; if (h < 1) return "Height must be at least one"; + if (w > INT_MAX / h) + return "Width times height must not be unreasonably large"; + wh = w * h; if (wh % k) return "Region size must divide grid area"; - if (!full) return NULL; /* succeed partial validation */ /* MAYBE FIXME: we (just?) don't have the UI for winning these. */