Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-59656

ksh segfaults when unsetting SHLVL then exec'ing

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Normal Normal
    • rhel-9.6
    • rhel-9.4, rhel-10.0.beta, eln
    • ksh
    • None
    • Yes
    • Moderate
    • rhel-sst-cs-plumbers
    • ssg_core_services
    • 5
    • False
    • Hide

      None

      Show
      None
    • None
    • Red Hat Enterprise Linux
    • None
    • None
    • None
    • All
    • None

      What were you trying to do that didn't work?

      In case the user unset SHLVL variable then later replaces the shell through executing a command, ksh will segfault:

      # unset -v SHLVL
      # exec bash
      Segmentation fault (core dumped)
      

      The reason for this is SHLVL variable is getting decremented without any guard making sure it's still in the environment, see ksh-1.0.6/src/cmd/ksh93/bltins/misc.c sources:

       70 /*
       71  * 'exec' special builtin and 'redirect' builtin
       72  */
       :
       77 int    b_exec(int argc,char *argv[], Shbltin_t *context)
       78 {
       :
      148                 /* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */
      149                 if(!sh.realsubshell)
      150                         (*SHLVL->nvalue.ip)--;
      

      What is the impact of this issue to you?

      Users unsetting SHLVL in the .profile file cannot login anymore.

      This is a regression introduced sometimes after ksh-1.0.0~beta.1-3.el9.

      Please provide the package NVR for which the bug is seen:

      ksh-1.0.6-3.el9

      How reproducible is this bug?:

      Always, see above.

              vmihalko Vincent Mihalkovic
              rhn-support-rmetrich Renaud Métrich
              Vincent Mihalkovic Vincent Mihalkovic
              Karel Volný Karel Volný
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated: