shithub: puzzles

Download patch

ref: 07999443c24414602cf046fefc84d1d17b5afd69
parent: 91d96fa0bc133c8d967f3c4b01804e7773de8504
author: Ben Harris <[email protected]>
date: Thu Jan 12 09:34:14 EST 2023

Limit size of puzzle in Tents to avoid integer overflow

--- a/tents.c
+++ b/tents.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <assert.h>
 #include <ctype.h>
+#include <limits.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -408,6 +409,8 @@
      */
     if (params->w < 4 || params->h < 4)
 	return "Width and height must both be at least four";
+    if (params->w > (INT_MAX - 1) / params->h)
+        return "Width times height must not be unreasonably large";
     return NULL;
 }