ksh: Crash when running `set` in a subshell/comsub with discipline function defined
set
outputs the values of all the variables. This crashes in the following reproducer:
function GIT_BRANCH.get
{
command -v git >/dev/null || return
.sh.value=${ git branch 2>/dev/null; }
case $'\n'${.sh.value} in
*$'\n* '*)
.sh.value=$'\n'${.sh.value}
.sh.value=${.sh.value#*$'\n* '}
.sh.value=${.sh.value%%$'\n'*}
;;
*) .sh.value=''
;;
esac
}
v=$(set)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 48
Commits related to this issue
- Fix $_ corruption in subshell disc functs (re: 88a1f3d6, 0a343244) The _ variable is used for various context-dependent things and is sometimes a name reference (see man page under Variables). The $_... — committed to ksh93/ksh by McDutchie a year ago
- Fix $_ corruption in subshell disc functs (re: 88a1f3d6, 430e4781) The _ variable is used for various context-dependent things and is sometimes a name reference (see man page under Variables). The $_... — committed to JohnoKing/ksh by McDutchie a year ago
Tested successful as described in issue with patch 5. I also checked my memory fault notes and did not find anything else to add to the mix.
Forgot to say, patch-five run like a champ on ubuntu 22.04 s390x as well.
patch-five runs like a champ 😃 you are a star!
Ha you beat me on this one, I learned how to monitor L_ARGNOD, thank you for that, and I discovered this.
I am not fluent enough with the setjmp/longjmp pushcontext/popcontext, I dunno how they are linked together etc… but I think if you manage set a setjmp/longjmp point so on error in sh_funct() we longjmp back to the restore point for L_ARGNOD, you would be safe and no need update set_instance() unset_instance() unless theire are bugged.
Well, dunno why I didn’t thought earlier, when I discovered that the name of the variable did matter, i.e
Z
is above_
andz
is below, I feared that interaction with discipline messing with_
andprint_nameval
accessing_
could be problematic.I decided to make a brutal kludge, i.e skipping over
_
inprint_scan
(src/cmd/ksh93/bltins/typeset.c)And to my grand surprise, no more core dump, and no regression in QA, even though now
b=$(set)
miss the_
variable, IMHO this is not a big lost and ledgitmate to withdraw, as we withdraw.sh
etc… the value of_
atset
time will be overloaded right afterb=$(set)
as_=$(set)
Anyway this means that may be all the things with fork() is still good, only the
_
access inprint_scan
is not good, I noticed that when not doing the kludge, i.e that actual prod path, then effectivlynp
pointer got corrupted data leading to crashdump.Is that a trail to follow ?
EDIT: Well now I got no core dump, but later
echo $_
do core dump, so_
is corrupted anyway, simply not being printed in the print_scan() differ it. So may be fork() is back 😃