Closed vmihalko closed 1 month ago
Why is SHLVL unsettable? Shouldn't that generate some sort of error?
Edit... NVM, the man page actually refers to a case where it's not in the environment, so it's on purpose.
Thanks for the report, @vmihalko. I prefer to fix it in a slightly different way. Commit coming up.
What happens?
If the user unsets the SHLVL variable and later replaces the shell by executing a command, ksh will segfault.
Reproducer
Reason
The reason for this is that the SHLVL variable is getting decremented without any guard making sure it's still in the environment, see: https://github.com/ksh93/ksh/blob/7170ac01c4f4603586661761ba685d2d3c2d69bc/src/cmd/ksh93/bltins/misc.c#L145-L147
Fix
I tested the following simple fix, and the segmentation fault no longer occurs.
Should I use some other way to test if SHLVL is set, or is this OK, and I can create a PR?