Email List: Xaustin-review-lX
[All Lists]

Defect in XCU cd

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XCU cd
From: Geoff Clare <yyy@xxxxxxxxxxxxx>
Date: Tue, 18 May 2004 16:28:51 +0100
(Page and line numbers are for the 2004 edition.)

@ page 226-227 line 8859-8887 section cd objection [gwc cd relative paths]

Problem:

Defect code :  1. Error

In SUSv3 there was a major revision of the description of the cd
utility in order to specify how symbolic links are handled.
Defects in some of the steps of the new description have been
identified during discussions on the Austin Group reflector.

Firstly, if the CDPATH search is either not done or fails then the
steps always end up converting a relative pathname to an absolute
pathname before it is passed to chdir(), which leads to two problems
when the cd operand is a relative pathname:

    * The standard apparently requires cd to fail (because chdir()
    would produce an ENAMETOOLONG error) under circumstances where
    existing practice is to convert back to a relative pathname in
    order to avoid the ENAMETOOLONG error.  The description should
    be amended to specify this conversion back to a relative
    pathname.

    * If PWD does not refer to the current directory (e.g. because
    another process renamed one of the directories within PWD) then
    changing to the absolute pathname "$PWD/cd_operand" would fail
    (or change to the wrong directory) whereas if the shell just
    called chdir(cd_operand) it would work correctly.  This is more
    of an issue when the -P option is in effect, since cd's logical
    directory handling is fundamentally dependent on PWD anyway.
    The description should be amended so that, when the CDPATH
    search is either not done or fails, a relative pathname used with
    "cd -P" is passed to chdir() "as is".  (Note that this would not
    prevent implementations from converting to an absolute pathname
    and back again internally.)

Secondly, the description of dot-dot removal does not match existing
practice, in that it does not include a check that the component
preceding the dot-dot refers (with symbolic links followed) to a
directory.

Thirdly, if the CDPATH search succeeds and the path used from CDPATH
is a relative path, and the -P option is not in effect, then PWD ends
up being set to a relative path.

Action:

Replace step 6 with the following:

    "6.  If the -P option is in effect, set curpath to the directory
         operand.  Otherwise, set curpath to the string formed by the
         concatenation of the value of PWD, a slash character, and the
         operand."

Replace step 7 with the following:

    "7.  If the -P option is in effect, proceed to step 10.
         If curpath does not begin with a slash character, set curpath
         to the string formed by the concatenation of the value of PWD,
         a slash character, and the operand."

(Note that most of the old step 7 text reappears in the new step 10
below.)

Replace step 8b with the following:

    "b.  For each dot-dot component, if there is a preceding component
         and it is neither root nor dot-dot, then:

           i.  If the preceding component does not refer (in the
           context of pathname resolution with symbolic links followed)
           to a directory, then the cd utility shall display an
           appropriate error message and no further steps shall be
           taken.

           ii. The preceding component, all slashes separating the
           preceding component from dot-dot, dot-dot and all slashes
           separating dot-dot from the following component (if any)
           shall be deleted."

Insert a new step 9:

    "9.  If curpath is longer than {PATH_MAX} bytes (including the
         terminating null) and the directory operand was not longer
         than {PATH_MAX} bytes (including the terminating null), then
         curpath shall be converted from an absolute pathname to an
         equivalent relative pathname if possible.  This conversion
         shall always be considered possible if the value of PWD, with
         a trailing slash added if it does not already have one, is an
         initial substring of curpath.  Whether or not it is
         considered possible under other circumstances is unspecified.
         Implementations may also apply this conversion if curpath is
         not longer than {PATH_MAX} bytes or the directory operand was
         longer than {PATH_MAX} bytes."

Replace the old step 9 with the following:

    "10. The cd utility shall then perform actions equivalent to the
         chdir() function called with curpath as the path argument.
         If these actions fail for any reason, the cd utility shall
         display an appropriate error message and the remainder of
         this step shall not be executed.  If the -P option is not in
         effect, the PWD environment variable shall be set to the
         value that curpath had on entry to step 9 (i.e. before
         conversion to a relative pathname).  If the -P option is in
         effect, the PWD environment variable shall be set to an
         absolute pathname for the current working directory and shall
         not contain filename components that, in the context of
         pathname resolution, refer to a file of type symbolic link.
         If there is insufficient permission on the new directory, or
         on any parent of that directory, to determine the current
         working directory, the value of the PWD environment variable
         is unspecified."

<Prev in Thread] Current Thread [Next in Thread>