-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash on 'exec' after 'unset SHLVL' (re: e5e1d4b)
Vincent Mihalkovič (@vmihalko) reports: > If the user unsets the SHLVL variable and later replaces the > shell by executing a command, ksh will segfault. > > Reproducer > > # unset -v SHLVL > # exec bash > Segmaentation fault (core dumped) > > 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: > > src/cmd/ksh93/bltins/misc.c: > 145: /* if the main shell is about to be replaced, decrease SHLVL > to cancel out a subsequent increase */ > 146: if(!sh.realsubshell) > 147: (*SHLVL->nvalue.ip)--; This should be fixed so that SHLVL can be unset safely and lose its special properties like other special variables do. src/cmd/ksh93/sh/init.c, src/cmd/ksh93/include/shell.h: - Move the static 'shlvl' in init.c to the sh state struct, so that 'sh.shlvl' can be accessed from the entire ksh93 code base. - Change its type from int to int32_t -- this is more correct as nv_getval() uses this type to retrieve the value. In practice, this makes no difference because sizeof(int) == sizeof(int32_t), but this is not guaranteed by the standards. src/cmd/ksh93/bltins/misc.c: - Access sh.shlvl directly instead of dereferencing the SHLVL value pointer, as this pointer is invalidated upon 'unset SHLVL'. This fixes the bug. Resolves: #788
- Loading branch information
Showing
6 changed files
with
19 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters