]> granicus.if.org Git - nethack/commitdiff
Fix findtravelpath buffer overflow
authorPasi Kallinen <paxed@alt.org>
Mon, 21 Dec 2015 16:18:28 +0000 (18:18 +0200)
committerPasi Kallinen <paxed@alt.org>
Mon, 21 Dec 2015 16:18:40 +0000 (18:18 +0200)
Test case: Bigroom, full of boulders, with a single
path from travel start to travel end. Boulders (and
doors) are added to the travelstep[xy] arrays multiple
times, and will overflow the arrays.

Original patch via Acehack by Alex Smith

src/hack.c

index a3886457c45cac03902aeda871b5d9bf534426e9..2f45d10fde66765137bbad418e53ecba6f82c441 100644 (file)
@@ -919,6 +919,7 @@ boolean guess;
                 static int ordered[] = { 0, 2, 4, 6, 1, 3, 5, 7 };
                 /* no diagonal movement for grid bugs */
                 int dirmax = NODIAG(u.umonnum) ? 4 : 8;
+                boolean alreadyrepeated = FALSE;
 
                 for (dir = 0; dir < dirmax; ++dir) {
                     int nx = x + xdir[ordered[dir]];
@@ -932,10 +933,13 @@ boolean guess;
                         /* closed doors and boulders usually
                          * cause a delay, so prefer another path */
                         if (travel[x][y] > radius - 3) {
-                            travelstepx[1 - set][nn] = x;
-                            travelstepy[1 - set][nn] = y;
-                            /* don't change travel matrix! */
-                            nn++;
+                            if (!alreadyrepeated) {
+                                travelstepx[1 - set][nn] = x;
+                                travelstepy[1 - set][nn] = y;
+                                /* don't change travel matrix! */
+                                nn++;
+                                alreadyrepeated = TRUE;
+                            }
                             continue;
                         }
                     }