]> granicus.if.org Git - nethack/commitdiff
Prevent accessing outside the mons array
authorPasi Kallinen <paxed@alt.org>
Fri, 20 Dec 2019 13:16:12 +0000 (15:16 +0200)
committerPasi Kallinen <paxed@alt.org>
Fri, 20 Dec 2019 13:19:14 +0000 (15:19 +0200)
doc/fixes37.0
src/minion.c

index 37627fafaf011b68db0dfeec47cf572f582d014e..41f7347a7b2258d5dfbe5654c1ed40ca9cbe857f 100644 (file)
@@ -12,6 +12,7 @@ fix internal self-recover to work with recent fields added to checkpoint file
 improvements to pronoun usage when hallucinating
 function calls made from mapglyph based on dungeon level are now called once
        per level
+fix accessing mons[-1] when trying to gate in a non-valid demon
 
 
 Fixes to Pre-3.7.0 Problems that Were Exposed Via git Repository
index 6a8a06ee78ad194afe4920bdbe8bf4e3d26067fd..dac4430a0ad693bcce75600109c91d0955053edf 100644 (file)
@@ -78,11 +78,13 @@ struct monst *mon;
     if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
         dtype = (!rn2(20)) ? dprince(atyp) : (!rn2(4)) ? dlord(atyp)
                                                        : ndemon(atyp);
-        cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
+        cnt = ((dtype != NON_PM)
+               && !rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
     } else if (is_dlord(ptr)) {
         dtype = (!rn2(50)) ? dprince(atyp) : (!rn2(20)) ? dlord(atyp)
                                                         : ndemon(atyp);
-        cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
+        cnt = ((dtype != NON_PM)
+               && !rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
     } else if (is_ndemon(ptr)) {
         dtype = (!rn2(20)) ? dlord(atyp) : (!rn2(6)) ? ndemon(atyp)
                                                      : monsndx(ptr);
@@ -91,7 +93,8 @@ struct monst *mon;
         dtype = (is_lord(ptr) && !rn2(20))
                     ? llord()
                     : (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
-        cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
+        cnt = ((dtype != NON_PM)
+               && !rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
     } else if (ptr == &mons[PM_ANGEL]) {
         /* non-lawful angels can also summon */
         if (!rn2(6)) {
@@ -107,7 +110,8 @@ struct monst *mon;
         } else {
             dtype = PM_ANGEL;
         }
-        cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
+        cnt = ((dtype != NON_PM)
+               && !rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
     }
 
     if (dtype == NON_PM)