From 61468486933853d8a45a1a5e03db03708d18b64c Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 28 Feb 2021 23:02:36 +0000 Subject: [PATCH] Fix compiling with SHOPT_REGRESS and SHOPT_P_SUID src/cmd/ksh93/Mamfile: - regress.c: add missing SH_DICT define for getopt self-doc string, needed after USAGE_LICENSE macros were removed. (re: ede47996) src/cmd/ksh93/init.c: sh_init(): - Do not set error_info.exit early in init. This is the function that is called when an error exits the shell. It defaults to exit(3). Setting it to sh_exit() early on can cause a crash if an error is thrown before shell initialisation is fully finished. So set it at the end of sh_init() instead. - __regress__: Remove error_info.exit workaround. (re: 506bd2b2) - Fix SHOPT_P_SUID directive. This is not actually a 0/1 value, so we should use #ifdef and not #if. If SHOPT_REGRESS is on, it it set to a function call. (re: 2182ecfa) src/cmd/ksh93/SHOPT.sh: - Document that SHOPT_P_SUID cannot be set to 0 to be turned off. --- src/cmd/ksh93/Mamfile | 2 +- src/cmd/ksh93/SHOPT.sh | 2 +- src/cmd/ksh93/sh/init.c | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cmd/ksh93/Mamfile b/src/cmd/ksh93/Mamfile index a6f242ef9..fdbf8a7f5 100644 --- a/src/cmd/ksh93/Mamfile +++ b/src/cmd/ksh93/Mamfile @@ -818,7 +818,7 @@ make install meta regress.o %.c>%.o bltins/regress.c regress prev bltins/regress.c prev SHOPT.sh - exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -D_BLD_shell -DKSHELL -DERROR_CONTEXT_T=Error_context_t -c bltins/regress.c + exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${KSH_SHOPTFLAGS} ${CCFLAGS} -DSH_DICT=${SH_DICT} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -D_BLD_shell -DKSHELL -DERROR_CONTEXT_T=Error_context_t -c bltins/regress.c done regress.o generated make fault.o make sh/fault.c diff --git a/src/cmd/ksh93/SHOPT.sh b/src/cmd/ksh93/SHOPT.sh index f03f8b762..e7f56a7a1 100644 --- a/src/cmd/ksh93/SHOPT.sh +++ b/src/cmd/ksh93/SHOPT.sh @@ -26,7 +26,7 @@ SHOPT NAMESPACE=1 # allow namespaces SHOPT OLDTERMIO= # support both TCGETA and TCGETS SHOPT OPTIMIZE=1 # optimize loop invariants SHOPT PFSH=0 # solaris exec_attr(4) profile execution (obsolete) -SHOPT P_SUID= # real uid's that require -p for set[ug]id +SHOPT P_SUID= # real uid's that require -p for set[ug]id (do not set to 0 to turn off) SHOPT RAWONLY=1 # make viraw the only vi mode SHOPT REGRESS= # enable __regress__ builtin and instrumented intercepts for testing SHOPT REMOTE= # enable --rc if running as a remote shell diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index a1f2794e7..caf16abd5 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1257,7 +1257,6 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) if(shgd->lim.clk_tck <=0) shgd->lim.clk_tck = CLK_TCK; shgd->ed_context = (void*)ed_open(shp); - error_info.exit = sh_exit; error_info.id = path_basename(argv[0]); } else @@ -1301,9 +1300,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) break; nopt = optctx(0, 0); oopt = optctx(nopt, 0); - error_info.exit = exit; /* avoid crash on b___regress__ error as shell is not fully initialized */ b___regress__(2, regress, &shp->bltindata); - error_info.exit = sh_exit; optctx(oopt, nopt); } } @@ -1462,7 +1459,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) /* set[ug]id scripts require the -p flag */ if(shp->gd->userid!=shp->gd->euserid || shp->gd->groupid!=shp->gd->egroupid) { -#if SHOPT_P_SUID +#ifdef SHOPT_P_SUID /* require sh -p to run setuid and/or setgid */ if(!sh_isoption(SH_PRIVILEGED) && shp->gd->userid >= SHOPT_P_SUID) { @@ -1527,6 +1524,7 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit) shp->exittrap = 0; shp->errtrap = 0; shp->end_fn = 0; + error_info.exit = sh_exit; return(shp); }