]> granicus.if.org Git - nethack/commitdiff
fit git issue #960 - out-of-bounds array access
authorPatR <rankin@nethack.org>
Sun, 22 Jan 2023 09:43:20 +0000 (01:43 -0800)
committerPatR <rankin@nethack.org>
Sun, 22 Jan 2023 09:43:20 +0000 (01:43 -0800)
Issue reported by argrath:  if getoptstr() executed its loop to
find the latest phase that set a role/race/gender/alignment option
value, the first iteration of the loop would use an index that's
out of bounds.

The code in question is wrong but happens to not be used, so the
out of bounds access doesn't occur.  Fix the value for the first
iteration in case the offending code eventually gets used.

Fixes #960

src/options.c

index 9245d48dee8da8ebf033167433fb29fdee0c7a49..3080086a95500b1ca0d9a6766468a61239c3563f 100644 (file)
@@ -617,7 +617,7 @@ getoptstr(int optidx, int ophase)
 
         /* find non-Null, in order optvals[][play_opt], [cmdline_opt],
            [environ_opt], [rc_file_opt], [syscf_opt], [builtin_opt] */
-        for (phase = num_opt_phases; phase >= 0; --phase)
+        for (phase = num_opt_phases - 1; phase >= 0; --phase)
             if (roleoptvals[roleoptindx][phase]) {
                 ophase = phase;
                 break;