bin/59530: strange bug in /bin/sh

Danny J. Zerkel dzerkel at columbus.rr.com
Fri Dec 19 20:10:23 PST 2003


The following reply was made to PR bin/59530; it has been noted by GNATS.

From: "Danny J. Zerkel" <dzerkel at columbus.rr.com>
To: freebsd-gnats-submit at FreeBSD.org, dima at KOT.SPb.Ru
Cc:  
Subject: Re: bin/59530: strange bug in /bin/sh
Date: Fri, 19 Dec 2003 23:04:16 -0500

 On further review, PWD and OLDPWD are not correctly handled by my
 previous patch.  So I offer the following update, which only sets
 the environment variables only if we succeed in changing directory:
 
 *** cd.c.orig   Fri Dec 19 22:51:26 2003
 --- cd.c        Fri Dec 19 22:57:58 2003
 ***************
 *** 155,160 ****
 --- 155,163 ----
          if ((phys || cdlogical(dest) < 0) && cdphysical(dest) < 0)
                  return (-1);
 
 +       setvar("PWD", curdir, VEXPORT);
 +       setvar("OLDPWD", prevdir, VEXPORT);
 +
          if (print && iflag && curdir)
                  out1fmt("%s\n", curdir);
 
 ***************
 *** 217,223 ****
    {
 
          INTOFF;
 !       if (chdir(dest) < 0 || updatepwd(NULL) < 0) {
                  INTON;
                  return (-1);
          }
 --- 220,231 ----
    {
 
          INTOFF;
 !       if (chdir(dest) < 0) {
 !               updatepwd(NULL);
 !               INTON;
 !               return (-1);
 !       }
 !       if (updatepwd(NULL) < 0) {
                  INTON;
                  return (-1);
          }
 ***************
 *** 278,285 ****
                          INTON;
                          return (-1);
                  }
 -               setvar("PWD", curdir, VEXPORT);
 -               setvar("OLDPWD", prevdir, VEXPORT);
                  INTON;
                  return (0);
          }
 --- 286,291 ----
 ***************
 *** 310,317 ****
                  ckfree(prevdir);
          prevdir = curdir;
          curdir = savestr(stackblock());
 -       setvar("PWD", curdir, VEXPORT);
 -       setvar("OLDPWD", prevdir, VEXPORT);
          INTON;
 
          return (0);
 --- 316,321 ----
 
 Danny J. Zerkel -- dzerkel at columbus.rr.com


More information about the freebsd-bugs mailing list