shithub: puzzles

Download patch

ref: b3f3345764b0808a7a97b9c3a2a1888fd62383a0
parent: 97484b098f33266f6c747c292c708281cb15a286
author: Ben Harris <[email protected]>
date: Tue Jan 10 19:03:57 EST 2023

Last-ditch grid-size limit for Dominosa

At least prevent integer overflow when constructing the grid.

--- 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 @@
 {
     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;