shithub: puzzles

Download patch

ref: d5ec2758ee3b7a8934475a1122813ad2312dc850
parent: b090c82df1527dcf348c96765f10ab5736c68c29
author: Ben Harris <bjh21@bjh21.me.uk>
date: Tue Jan 10 05:54:37 EST 2023

Last-ditch maximum size limit for Same Game

This makes sure that width * height <= INT_MAX, which it rather needs
to be.

--- a/samegame.c
+++ b/samegame.c
@@ -67,6 +67,7 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -285,6 +286,8 @@
 {
     if (params->w < 1 || params->h < 1)
 	return "Width and height must both be positive";
+    if (params->w > INT_MAX / params->h)
+        return "Width times height must not be unreasonably large";
 
     if (params->ncols > 9)
 	return "Maximum of 9 colours";