From 550845c3a17ee29a995cbdaa8a7405267392beb8 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 22 Jan 2023 01:43:20 -0800 Subject: [PATCH] fit git issue #960 - out-of-bounds array access 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/options.c b/src/options.c index 9245d48de..3080086a9 100644 --- a/src/options.c +++ b/src/options.c @@ -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;