From debbugs-submit-bounces@debbugs.gnu.org Fri May 11 14:12:04 2012 Received: (at submit) by debbugs.gnu.org; 11 May 2012 18:12:04 +0000 Received: from localhost ([127.0.0.1]:49380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSuJw-0005J0-Ak for submit@debbugs.gnu.org; Fri, 11 May 2012 14:12:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56919) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSuJt-0005IV-V0 for submit@debbugs.gnu.org; Fri, 11 May 2012 14:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSuJh-00019l-Al for submit@debbugs.gnu.org; Fri, 11 May 2012 14:11:50 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:51736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSuJh-00019h-7Z for submit@debbugs.gnu.org; Fri, 11 May 2012 14:11:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSuJf-0002Go-Ls for bug-coreutils@gnu.org; Fri, 11 May 2012 14:11:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSuJd-00019U-U0 for bug-coreutils@gnu.org; Fri, 11 May 2012 14:11:47 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:52350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSuJd-00019P-Nw for bug-coreutils@gnu.org; Fri, 11 May 2012 14:11:45 -0400 Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id C84D01B4012 for ; Fri, 11 May 2012 18:11:43 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: bug-coreutils@gnu.org Subject: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / Date: Fri, 11 May 2012 14:11:54 -0400 User-Agent: KMail/1.13.7 (Linux/3.4.0-rc6; KDE/4.6.5; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2808080.yYDXOqSTjU"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201205111411.55649.vapier@gentoo.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.17 X-Spam-Score: -6.1 (------) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.1 (------) --nextPart2808080.yYDXOqSTjU Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug=20 before, so looks like a regression with 8.17 easy to show: $ sudo ln -s dev /foo $ ls --color=3Dauto / =2E.. foo wrongly shows up in blinky text indicating it's a broken symlink = =2E.. $ ls --color=3Dauto /. =2E.. foo correctly shows up with normal coloring indicating it's a symlink= ... $ cd / ; ls --color=3Dauto =2E.. foo correctly shows up with normal coloring indicating it's a symlink= ... =2Dmike --nextPart2808080.yYDXOqSTjU Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJPrVZrAAoJEEFjO5/oN/WB0yEP/22koxYqGbAGupHJjz6vXUC6 AqmXV7GklMGe/glZU7qMWC1+5aKzDkURg4bh31XN1qQTzEq8dI3dBP+o7oPxNhCX 2QuajupA9oG7ZYzKrfYyts62olHoz1HqRcyhTQCSrj6ddY2f7J+8W2DFikduKJHN 2FU/1aeD06Ho3XHyttkbqsQmq/SYzRPbiWOv6IqzPWXcfq8sxrV9yPCTTlAKaGd+ Tn2Gn0lg6k+8J3QBe22UvCDimsmp6ckbiLvEuPygEJVl5voDJWBmDM3BkWJutYSX Qal8x10ztkT6JkzfXdaln32HTtS/Yy9DgATFltZkZB+m+QDQ22wrkhvP4oMox+6y AG5YSFJQH42khs42QpebLR7G1ssOI/cntPOwmUdxn099xG5ckPKoMafAx2/LzLR/ OqMlduz/gCu0zU0Ae1v2bSUuUzB3xpkHWASiUrSel6/hF2Qk3v7o9IOaHItr2U62 ixTzLD7K5h8HF1weqOyKz1ceg+PicfniVQu35VuMjX1iKxmoHoPbkoWxeQMZL5qx u9PEYwioS2O9lpqKqrVTmvG4IQnmfA/wVqyrD1Kod3MmXEsNKQCJmljBS7ElmcVk DFVOoJIBz6RZ+ogqrxWhdty2nS2pctUAa14fRkWPkBhOU3pPe9T4XqnGJUYykDek 7ka3N4sgVLjwxwRJb1qa =bZms -----END PGP SIGNATURE----- --nextPart2808080.yYDXOqSTjU-- From debbugs-submit-bounces@debbugs.gnu.org Fri May 11 14:48:45 2012 Received: (at 11453) by debbugs.gnu.org; 11 May 2012 18:48:45 +0000 Received: from localhost ([127.0.0.1]:49403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSutR-0006AJ-8H for submit@debbugs.gnu.org; Fri, 11 May 2012 14:48:45 -0400 Received: from mx.meyering.net ([88.168.87.75]:34587) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSutO-0006AA-0P for 11453@debbugs.gnu.org; Fri, 11 May 2012 14:48:43 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 4AA116004B; Fri, 11 May 2012 20:48:33 +0200 (CEST) From: Jim Meyering To: Mike Frysinger Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / In-Reply-To: <201205111411.55649.vapier@gentoo.org> (Mike Frysinger's message of "Fri, 11 May 2012 14:11:54 -0400") References: <201205111411.55649.vapier@gentoo.org> Date: Fri, 11 May 2012 20:48:33 +0200 Message-ID: <87d36alfjy.fsf@rho.meyering.net> Lines: 32 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11453 Cc: 11453@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Mike Frysinger wrote: > coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug > before, so looks like a regression with 8.17 > > easy to show: > $ sudo ln -s dev /foo > $ ls --color=auto / > ... foo wrongly shows up in blinky text indicating it's a broken symlink ... > $ ls --color=auto /. > ... foo correctly shows up with normal coloring indicating it's a symlink ... > $ cd / ; ls --color=auto > ... foo correctly shows up with normal coloring indicating it's a symlink ... > -mike Rats. That bug was introduced by my clean-up. Here's the probable fix. Thanks for the report! diff --git a/src/ls.c b/src/ls.c index 397e4ea..b548382 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3213,7 +3213,8 @@ make_link_name (char const *name, char const *linkname) return xstrdup (linkname); char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); + bool prefix_ends_in_slash = ISSLASH (name[prefix_len - 1]); + stpcpy (stpncpy (p, name, prefix_len + !prefix_ends_in_slash), linkname); return p; } From debbugs-submit-bounces@debbugs.gnu.org Fri May 11 15:02:57 2012 Received: (at 11453) by debbugs.gnu.org; 11 May 2012 19:02:57 +0000 Received: from localhost ([127.0.0.1]:49425 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSv7A-0006VN-LT for submit@debbugs.gnu.org; Fri, 11 May 2012 15:02:57 -0400 Received: from mx.meyering.net ([88.168.87.75]:34629) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSv78-0006VG-S4 for 11453@debbugs.gnu.org; Fri, 11 May 2012 15:02:55 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 58495600B3; Fri, 11 May 2012 21:02:47 +0200 (CEST) From: Jim Meyering To: Mike Frysinger Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / In-Reply-To: <87d36alfjy.fsf@rho.meyering.net> (Jim Meyering's message of "Fri, 11 May 2012 20:48:33 +0200") References: <201205111411.55649.vapier@gentoo.org> <87d36alfjy.fsf@rho.meyering.net> Date: Fri, 11 May 2012 21:02:47 +0200 Message-ID: <877gwilew8.fsf@rho.meyering.net> Lines: 33 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11453 Cc: 11453@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Jim Meyering wrote: > Mike Frysinger wrote: >> coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug >> before, so looks like a regression with 8.17 >> >> easy to show: >> $ sudo ln -s dev /foo >> $ ls --color=auto / >> ... foo wrongly shows up in blinky text indicating it's a broken symlink ... >> $ ls --color=auto /. >> ... foo correctly shows up with normal coloring indicating it's a symlink ... >> $ cd / ; ls --color=auto >> ... foo correctly shows up with normal coloring indicating it's a symlink ... >> -mike > > Rats. > That bug was introduced by my clean-up. > Here's the probable fix. > Thanks for the report! > > diff --git a/src/ls.c b/src/ls.c > index 397e4ea..b548382 100644 > --- a/src/ls.c > +++ b/src/ls.c > @@ -3213,7 +3213,8 @@ make_link_name (char const *name, char const *linkname) > return xstrdup (linkname); > > char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); > - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); > + bool prefix_ends_in_slash = ISSLASH (name[prefix_len - 1]); > + stpcpy (stpncpy (p, name, prefix_len + !prefix_ends_in_slash), linkname); Humph. That's wrong, too. From debbugs-submit-bounces@debbugs.gnu.org Fri May 11 15:12:35 2012 Received: (at 11453) by debbugs.gnu.org; 11 May 2012 19:12:36 +0000 Received: from localhost ([127.0.0.1]:49429 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvGV-0006iZ-7s for submit@debbugs.gnu.org; Fri, 11 May 2012 15:12:35 -0400 Received: from mx.meyering.net ([88.168.87.75]:34661) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvGS-0006iQ-1a for 11453@debbugs.gnu.org; Fri, 11 May 2012 15:12:33 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 814BD60157; Fri, 11 May 2012 21:12:24 +0200 (CEST) From: Jim Meyering To: Mike Frysinger Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / In-Reply-To: <87d36alfjy.fsf@rho.meyering.net> (Jim Meyering's message of "Fri, 11 May 2012 20:48:33 +0200") References: <201205111411.55649.vapier@gentoo.org> <87d36alfjy.fsf@rho.meyering.net> Date: Fri, 11 May 2012 21:12:24 +0200 Message-ID: <871umqleg7.fsf@rho.meyering.net> Lines: 64 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11453 Cc: 11453@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Jim Meyering wrote: > Mike Frysinger wrote: >> coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug >> before, so looks like a regression with 8.17 >> >> easy to show: >> $ sudo ln -s dev /foo >> $ ls --color=auto / >> ... foo wrongly shows up in blinky text indicating it's a broken symlink ... >> $ ls --color=auto /. >> ... foo correctly shows up with normal coloring indicating it's a symlink ... >> $ cd / ; ls --color=auto >> ... foo correctly shows up with normal coloring indicating it's a symlink ... >> -mike > > Rats. > That bug was introduced by my clean-up. > Here's the probable fix. > Thanks for the report! > > diff --git a/src/ls.c b/src/ls.c > index 397e4ea..b548382 100644 > --- a/src/ls.c > +++ b/src/ls.c > @@ -3213,7 +3213,8 @@ make_link_name (char const *name, char const *linkname) > return xstrdup (linkname); > > char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); > - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); > + bool prefix_ends_in_slash = ISSLASH (name[prefix_len - 1]); > + stpcpy (stpncpy (p, name, prefix_len + !prefix_ends_in_slash), linkname); While the above fixes your problem, it fails to solve the problem when running e.g., mkdir -p d/b; (cd d; ln -s b link); ls --color d (i.e., with a single-component base directory name and a symlink to a relative name it would still color "link" as if it were dangling) This fixes both: diff --git a/src/ls.c b/src/ls.c index 397e4ea..93a3338 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3206,14 +3206,9 @@ make_link_name (char const *name, char const *linkname) if (IS_ABSOLUTE_FILE_NAME (linkname)) return xstrdup (linkname); - /* The link is to a relative name. Prepend any leading directory - in 'name' to the link name. */ - size_t prefix_len = dir_len (name); - if (prefix_len == 0) - return xstrdup (linkname); - - char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); + char *d = dir_name (name); + char *p = file_name_concat (d, linkname, NULL); + free (d); return p; } From debbugs-submit-bounces@debbugs.gnu.org Fri May 11 15:46:09 2012 Received: (at 11453) by debbugs.gnu.org; 11 May 2012 19:46:09 +0000 Received: from localhost ([127.0.0.1]:49443 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvmz-0007TX-1o for submit@debbugs.gnu.org; Fri, 11 May 2012 15:46:09 -0400 Received: from mx.meyering.net ([88.168.87.75]:34765) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvmf-0007Se-7B for 11453@debbugs.gnu.org; Fri, 11 May 2012 15:45:50 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id A37AB6029E; Fri, 11 May 2012 21:45:40 +0200 (CEST) From: Jim Meyering To: Mike Frysinger Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / In-Reply-To: <871umqleg7.fsf@rho.meyering.net> (Jim Meyering's message of "Fri, 11 May 2012 21:12:24 +0200") References: <201205111411.55649.vapier@gentoo.org> <87d36alfjy.fsf@rho.meyering.net> <871umqleg7.fsf@rho.meyering.net> Date: Fri, 11 May 2012 21:45:40 +0200 Message-ID: <87vck2jycb.fsf@rho.meyering.net> Lines: 68 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11453 Cc: 11453@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Jim Meyering wrote: > Jim Meyering wrote: >> Mike Frysinger wrote: >>> coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug >>> before, so looks like a regression with 8.17 >>> >>> easy to show: >>> $ sudo ln -s dev /foo >>> $ ls --color=auto / >>> ... foo wrongly shows up in blinky text indicating it's a broken symlink ... >>> $ ls --color=auto /. >>> ... foo correctly shows up with normal coloring indicating it's a symlink ... >>> $ cd / ; ls --color=auto >>> ... foo correctly shows up with normal coloring indicating it's a symlink ... >>> -mike >> >> Rats. >> That bug was introduced by my clean-up. >> Here's the probable fix. >> Thanks for the report! >> >> diff --git a/src/ls.c b/src/ls.c >> index 397e4ea..b548382 100644 >> --- a/src/ls.c >> +++ b/src/ls.c >> @@ -3213,7 +3213,8 @@ make_link_name (char const *name, char const *linkname) >> return xstrdup (linkname); >> >> char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); >> - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); >> + bool prefix_ends_in_slash = ISSLASH (name[prefix_len - 1]); >> + stpcpy (stpncpy (p, name, prefix_len + !prefix_ends_in_slash), linkname); > > While the above fixes your problem, it fails to > solve the problem when running e.g., > > mkdir -p d/b; (cd d; ln -s b link); ls --color d Actually the above is fine after all -- and it uses less memory than the patch below. I must have been testing something else. > (i.e., with a single-component base directory name and a symlink > to a relative name it would still color "link" as if it were dangling) > > This fixes both: > > diff --git a/src/ls.c b/src/ls.c > index 397e4ea..93a3338 100644 > --- a/src/ls.c > +++ b/src/ls.c > @@ -3206,14 +3206,9 @@ make_link_name (char const *name, char const *linkname) > if (IS_ABSOLUTE_FILE_NAME (linkname)) > return xstrdup (linkname); > > - /* The link is to a relative name. Prepend any leading directory > - in 'name' to the link name. */ > - size_t prefix_len = dir_len (name); > - if (prefix_len == 0) > - return xstrdup (linkname); > - > - char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); > - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); > + char *d = dir_name (name); > + char *p = file_name_concat (d, linkname, NULL); > + free (d); > return p; > } From debbugs-submit-bounces@debbugs.gnu.org Sat May 12 10:28:08 2012 Received: (at 11453-done) by debbugs.gnu.org; 12 May 2012 14:28:08 +0000 Received: from localhost ([127.0.0.1]:50380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1STDIl-00014q-FS for submit@debbugs.gnu.org; Sat, 12 May 2012 10:28:08 -0400 Received: from mx.meyering.net ([88.168.87.75]:39489) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1STDIQ-000146-K3 for 11453-done@debbugs.gnu.org; Sat, 12 May 2012 10:28:06 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 8FF8660056; Sat, 12 May 2012 16:27:33 +0200 (CEST) From: Jim Meyering To: Mike Frysinger Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / In-Reply-To: <877gwilew8.fsf@rho.meyering.net> (Jim Meyering's message of "Fri, 11 May 2012 21:02:47 +0200") References: <201205111411.55649.vapier@gentoo.org> <87d36alfjy.fsf@rho.meyering.net> <877gwilew8.fsf@rho.meyering.net> Date: Sat, 12 May 2012 16:27:33 +0200 Message-ID: <87ipg1jwyy.fsf@rho.meyering.net> Lines: 181 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 11453-done Cc: 11453-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -1.9 (-) Jim Meyering wrote: > Jim Meyering wrote: >> Mike Frysinger wrote: >>> coreutils-8.16 works fine (confirmed), and i don't recall seeing this bug >>> before, so looks like a regression with 8.17 >>> >>> easy to show: >>> $ sudo ln -s dev /foo >>> $ ls --color=auto / >>> ... foo wrongly shows up in blinky text indicating it's a broken symlink ... >>> $ ls --color=auto /. >>> ... foo correctly shows up with normal coloring indicating it's a symlink ... >>> $ cd / ; ls --color=auto >>> ... foo correctly shows up with normal coloring indicating it's a symlink ... >>> -mike >> >> Rats. >> That bug was introduced by my clean-up. >> Here's the probable fix. >> Thanks for the report! >> >> diff --git a/src/ls.c b/src/ls.c >> index 397e4ea..b548382 100644 >> --- a/src/ls.c >> +++ b/src/ls.c >> @@ -3213,7 +3213,8 @@ make_link_name (char const *name, char const *linkname) >> return xstrdup (linkname); >> >> char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); >> - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); >> + bool prefix_ends_in_slash = ISSLASH (name[prefix_len - 1]); >> + stpcpy (stpncpy (p, name, prefix_len + !prefix_ends_in_slash), linkname); > > Humph. That's wrong, too. Actually it's fine. Here's that same semantic change, presented in a more readable manner, along with NEWS and a new test. The only way I found to reproduce this problem without write access to "/" is if there's already an entry there that is a non-dangling symlink-to-relative-name. Since those exist on Fedora 17 (/lib -> /usr/lib, /bin -> /usr/bin, etc.) and on Debian unstable, (I see relative vmlinuz and initrd.img links), that seems good enough. It's not worth the cost of an additional root-only test just to ensure this bug doesn't sneak back in. >From 6124a3842dfa8484b52e067a8ab8105c3875a4f7 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 10 May 2012 19:43:00 +0200 Subject: [PATCH] ls: color each symlink-to-relative-name in / properly In order for ls --color to color each symlink, it must form the name of each referent and then stat it to see if the link is dangling, to a directory, to a file, etc. When the symlink is to a relative name, ls must concatenate the starting directory name and that relative name. When, in addition, the starting directory was "/" or "/some-name", the result was ill-formed, and the subsequent stat would usually fail, making the caller color it as a dangling symlink. * src/ls.c (make_link_name): Don't botch the case in which dir_name(NAME) == "/" and LINKNAME is relative. * tests/ls/root-rel-symlink-color: New file. Test for the above. * tests/Makefile.am (TESTS): Add it. * NEWS (Bug fixes): Mention it. Reported by Mike Frysinger in http://bugs.gnu.org/11453 Bug introduced by commit v8.16-23-gbcb9078. --- NEWS | 5 ++++ src/ls.c | 9 +++++++- tests/Makefile.am | 1 + tests/ls/root-rel-symlink-color | 51 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 tests/ls/root-rel-symlink-color diff --git a/NEWS b/NEWS index 6c620b3..f9e9c70 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,11 @@ GNU coreutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Bug fixes + + ls --color would mis-color relative-named symlinks in / + [bug introduced in coreutils-8.17] + * Noteworthy changes in release 8.17 (2012-05-10) [stable] diff --git a/src/ls.c b/src/ls.c index 397e4ea..9494ae9 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3213,7 +3213,14 @@ make_link_name (char const *name, char const *linkname) return xstrdup (linkname); char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1); - stpcpy (stpncpy (p, name, prefix_len + 1), linkname); + + /* PREFIX_LEN usually specifies a string not ending in slash. + In that case, extend it by one, since the next byte *is* a slash. + Otherwise, the prefix is "/", so leave the length unchanged. */ + if ( ! ISSLASH (name[prefix_len - 1])) + ++prefix_len; + + stpcpy (stpncpy (p, name, prefix_len), linkname); return p; } diff --git a/tests/Makefile.am b/tests/Makefile.am index a4370a6..0bafc5f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -449,6 +449,7 @@ TESTS = \ ls/proc-selinux-segfault \ ls/readdir-mountpoint-inode \ ls/recursive \ + ls/root-rel-symlink-color \ ls/rt-1 \ ls/slink-acl \ ls/stat-dtype \ diff --git a/tests/ls/root-rel-symlink-color b/tests/ls/root-rel-symlink-color new file mode 100755 index 0000000..d795432 --- /dev/null +++ b/tests/ls/root-rel-symlink-color @@ -0,0 +1,51 @@ +#!/bin/sh +# Exercise the 8.17 ls bug with coloring relative-named symlinks in "/". + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ ls + +symlink_to_rel= +for i in /*; do + # Skip non-symlinks: + env test -h "$i" || continue + + # Skip dangling symlinks: + env test -e "$i" || continue + + # Skip any symlink-to-absolute-name: + case $(readlink "$i") in /*) continue ;; esac + + symlink_to_rel=$i + break +done + +test -z "$symlink_to_rel" \ + && skip_ no relative symlink in / + +e='\33' +color_code='01;36' +c_pre="$e[0m$e[${color_code}m" +c_post="$e[0m" +printf "$c_pre$symlink_to_rel$c_post\n" > exp || framework_failure_ + +env TERM=xterm LS_COLORS="ln=$color_code:or=1;31;42" \ + ls -d --color=always "$symlink_to_rel" > out || fail=1 + +compare exp out || fail=1 + +Exit $fail -- 1.7.10.2.484.gcd07cc5 From debbugs-submit-bounces@debbugs.gnu.org Mon May 14 08:44:28 2012 Received: (at 11453) by debbugs.gnu.org; 14 May 2012 12:44:28 +0000 Received: from localhost ([127.0.0.1]:52324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1STudX-00060I-4a for submit@debbugs.gnu.org; Mon, 14 May 2012 08:44:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14450) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1STudT-0005zq-DY for 11453@debbugs.gnu.org; Mon, 14 May 2012 08:44:25 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4ECht90001226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 May 2012 08:43:55 -0400 Received: from [10.3.113.93] (ovpn-113-93.phx2.redhat.com [10.3.113.93]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4EChsOM005020; Mon, 14 May 2012 08:43:55 -0400 Message-ID: <4FB0FE09.2040509@redhat.com> Date: Mon, 14 May 2012 06:43:53 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: 11453@debbugs.gnu.org, jim@meyering.net Subject: Re: bug#11453: `ls` in coreutils-8.17 incorrectly shows broken symlinks in / References: <201205111411.55649.vapier@gentoo.org> <87d36alfjy.fsf@rho.meyering.net> <877gwilew8.fsf@rho.meyering.net> <87ipg1jwyy.fsf@rho.meyering.net> In-Reply-To: <87ipg1jwyy.fsf@rho.meyering.net> X-Enigmail-Version: 1.4.1 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigE2ABB9BFBC3FDDF2904C93C0" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Spam-Score: -6.9 (------) X-Debbugs-Envelope-To: 11453 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.9 (------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigE2ABB9BFBC3FDDF2904C93C0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 05/12/2012 08:27 AM, Jim Meyering wrote: > Subject: [PATCH] ls: color each symlink-to-relative-name in / properly >=20 > In order for ls --color to color each symlink, it must form the name > of each referent and then stat it to see if the link is dangling, to > a directory, to a file, etc. When the symlink is to a relative name, > ls must concatenate the starting directory name and that relative name.= > When, in addition, the starting directory was "/" or "/some-name", > the result was ill-formed, and the subsequent stat would usually fail, > making the caller color it as a dangling symlink. Ooh, sounds like I'd better check that cygwin properly handles symlinks relative to / vs. // (although cygwin doesn't permit the creation of symlinks in // proper, as that directory is a read-only representation of other networked machines accessible at the moment). --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigE2ABB9BFBC3FDDF2904C93C0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPsP4KAAoJEKeha0olJ0NqZlIH+wbjKTGsHHRQhfViEwcsNnKs CmYkBombZ/CInKrYQ29lxZ6X2ZYCZq8hIMNhkdTgswS0wAwmZUKFHRqEmwPfVAcy W3olHMIP3mdENHR4bbAplAybuIDkhLHjlaDllhfxu5rA4qvNyGiCdLQljVdVIxCe 5ZkI9x4R+qT+R6NhAs2cnFbnq/n0fFEU6BCBd6etG3izT+Qrb7sK7wPcUN7NQ9/f q4L00hJKoXZkUy0MOWLqS9m7N/e1oc+SpO9j8Xw3YZx0ZcGgmzQ3DFerlmE551EE cql9YT14nkJ4AK/Qx6Zb3JZg4AazOvjMWmkZI2p6Rof7K4ySQlAhZvTzRBeeizA= =zwmc -----END PGP SIGNATURE----- --------------enigE2ABB9BFBC3FDDF2904C93C0-- From unknown Tue Aug 19 02:52:39 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 12 Jun 2012 11:24:02 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator