From ab3f1014cea6f37dacdf4b314eb55dd465d7a3f2 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Wed, 4 Jan 2023 18:31:09 -0800
Subject: [PATCH] Range-check the cfg.new_shell value before using as index
 into array

If a configuration had *no* command shells, this would have caused a crash here in SCFG.

Also, when selecting the new user command shell, default to the current selection.
---
 src/sbbs3/scfg/scfgsys.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/sbbs3/scfg/scfgsys.c b/src/sbbs3/scfg/scfgsys.c
index 10f8482d4c..a50527bc92 100644
--- a/src/sbbs3/scfg/scfgsys.c
+++ b/src/sbbs3/scfg/scfgsys.c
@@ -958,7 +958,7 @@ void sys_cfg(void)
 					sprintf(opt[i++],"%-27.27s%s","Editor"
 						,cfg.new_xedit);
 					sprintf(opt[i++],"%-27.27s%s","Command Shell"
-						,cfg.shell[cfg.new_shell]->code);
+						,cfg.new_shell >= cfg.total_shells ? "<invalid>" : cfg.shell[cfg.new_shell]->code);
 					if(cfg.new_prot!=' ')
 						sprintf(str,"%c",cfg.new_prot);
 					else
@@ -1123,7 +1123,7 @@ void sys_cfg(void)
 							for(i=0;i<cfg.total_shells && i<MAX_OPTS;i++)
 								sprintf(opt[i],"%-.*s", LEN_CODE, cfg.shell[i]->code);
 							opt[i][0]=0;
-							i=0;
+							i=cfg.new_shell;
 							uifc.helpbuf=
 								"`New User Command Shell:`\n"
 								"\n"
-- 
GitLab