Re: sh bug

From: Denis Antrushin <DAntrushin_at_mail.ru>
Date: Thu, 25 Mar 2004 10:50:30 +0300
Amar Takhar wrote:
> On 2004-03-22 20:46 +0600, a.s. mitrohin wrote:
> 
>>helo.
>>
>>builtin cd unable change work directory buf curdir grow anyway.
>>
> 
> I found this bug as well years back and ended up mentioning it to Jeff Roberson,
> I'm not sure how far he got on figuring out what it was.  He did have some
> idea's though.  It happens in more than just 'sh', sevral shell's have this
> issue so i'm not sure that it's a problem with sh.
In /usr/src/bin/sh/cd.c (cdlogical(), at line 206):

         INTOFF;
         if (updatepwd(badstat ? NULL : dest) < 0 || chdir(curdir) < 0) {
                 INTON;
                 return (-1);
         }
         INTON;
         return(0);

Here, updatepwd() updates curdir and prevdir variables and *after* that
sh tries to actually change current directory.  And when chdir() fails,
we don't revert curdir/prevdir changes. :-)


> 
> I'd go with Kris's suggestion and file a PR.
> 
> 
> Amar.
Received on Wed Mar 24 2004 - 22:52:22 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:48 UTC