Skip to content

Commit

Permalink
Fix error in special bltin disabling .sh.tilde disc (re: 3c2b0dc)
Browse files Browse the repository at this point in the history
Since sh_exit() in fault.c now sets sh.tilde_block to 0, an error
in a special built-in will set that to 0. Then the tilde expansion
completes and sh.tilde_block is decreased in tilde_expand2().
Meaning it gets decreased after being set to 0, so it gets
permanently blocked due to its value -1.

The simplest fix is to explicitly set sh.tilde_block to 1 and 0
instead of increasing and decreasing it.
  • Loading branch information
McDutchie committed Sep 24, 2023
1 parent 8cc9a13 commit e9182bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2023-09-16" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2023-09-24" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2023 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -2717,10 +2717,10 @@ static void tilde_expand2(int offset)
if(!sh.tilde_block && SH_TILDENOD->nvfun && SH_TILDENOD->nvfun->disc)
{
stkfreeze(sh.stk,1); /* terminate current stack object to avoid data corruption */
sh.tilde_block++;
sh.tilde_block = 1;
nv_putval(SH_TILDENOD, &stakp[offset], 0);
cp = nv_getval(SH_TILDENOD);
sh.tilde_block--;
sh.tilde_block = 0;
if(cp[0]=='\0' || cp[0]=='~')
cp = NULL; /* do not use empty or unexpanded result */
stkset(sh.stk,stakp,curoff); /* restore stack to state on function entry */
Expand Down
17 changes: 17 additions & 0 deletions src/cmd/ksh93/tests/tilde.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,22 @@ do (
fi
done

# ======

got=$(
.sh.tilde.get()
{
case ${.sh.tilde} in
"~ksh") .sh.value=/usr/local/src/ksh93/ksh ;;
"~ers") trap -Q; .sh.value=BAD ;; #test
esac
}
{ : ~ers; } 2>/dev/null
echo ~ksh
)
exp=/usr/local/src/ksh93/ksh
[[ $got == "$exp" ]] || err_exit "error in special builtin disables .sh.tilde discipline" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"

# ======
exit $((Errors<125?Errors:125))

0 comments on commit e9182bd

Please sign in to comment.