GNU bug report logs - #20795
[PATCH] Fix behavior of --follow-symlinks on stdin

Previous Next

Package: sed;

Reported by: Stanislav Brabec <sbrabec <at> suse.com>

Date: Fri, 12 Jun 2015 15:32:01 UTC

Severity: normal

Tags: patch

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20795 in the body.
You can then email your comments to 20795 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#20795; Package sed. (Fri, 12 Jun 2015 15:32:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stanislav Brabec <sbrabec <at> suse.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Fri, 12 Jun 2015 15:32:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stanislav Brabec <sbrabec <at> suse.com>
To: bug-sed <at> gnu.org
Subject: [PATCH] Fix behavior of --follow-symlinks on stdin
Date: Fri, 12 Jun 2015 17:30:25 +0200
When reading from stdin, --follow-symlinks causes failure.
Prevent follow_symlink("-").

How to reproduce:
echo abc | sed --follow-symlinks s/a/d/
sed: cannot stat -: No such file or directory

Signed-off-by: Stanislav Brabec <sbrabec <at> suse.com>
---
 sed/execute.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/sed/execute.c b/sed/execute.c
index 4ddbf55..bfde525 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -549,6 +549,7 @@ open_next_file(const char *name, struct input *input)
 {
   buffer.length = 0;
 
+  input->in_file_name = name;
   if (name[0] == '-' && name[1] == '\0' && !in_place_extension)
     {
       clearerr(stdin);	/* clear any stale EOF indication */
@@ -559,22 +560,23 @@ open_next_file(const char *name, struct input *input)
       input->fp = stdin;
 #endif
     }
-  else if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
+  else
     {
-      const char *ptr = strerror(errno);
-      fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
-      input->read_fn = read_always_fail; /* a redundancy */
-      ++input->bad_count;
-      return;
+      if (follow_symlinks)
+        input->in_file_name = follow_symlink (name);
+
+      if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
+        {
+          const char *ptr = strerror(errno);
+          fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
+          input->read_fn = read_always_fail; /* a redundancy */
+          ++input->bad_count;
+          return;
+        }
     }
 
   input->read_fn = read_file_line;
 
-  if (follow_symlinks)
-    input->in_file_name = follow_symlink (name);
-  else
-    input->in_file_name = name;
-
   if (in_place_extension)
     {
       int input_fd;
-- 
2.4.2

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec <at> suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76




Information forwarded to bug-sed <at> gnu.org:
bug#20795; Package sed. (Mon, 13 Jul 2015 21:00:06 GMT) Full text and rfc822 format available.

Message #8 received at 20795 <at> debbugs.gnu.org (full text, mbox):

From: Stanislav Brabec <sbrabec <at> suse.com>
To: 20795 <at> debbugs.gnu.org
Subject: Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on
 stdin
Date: Mon, 13 Jul 2015 22:59:17 +0200
When reading from stdin, --follow-symlinks causes failure since
v4.2.1-13-g84066bf:
echo abc | sed --follow-symlinks s/a/d/
sed: cannot stat -: No such file or directory

Never call follow_symlink("-") to prevent this problem.
http://bugs.gnu.org/20795
---
 NEWS                               |  3 +++
 sed/execute.c                      | 24 +++++++++++++-----------
 testsuite/Makefile.am              |  1 +
 testsuite/follow-symlinks-stdin.sh | 29 +++++++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 11 deletions(-)
 create mode 100644 testsuite/follow-symlinks-stdin.sh

diff --git a/NEWS b/NEWS
index 61b8aa2..6367dea 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,9 @@ GNU sed NEWS                                    -*- outline -*-
   leaves behind a temporary file.  Before, that command would create a file
   alongside F with a name matching /^sed......$/ and fail to remove it.
 
+  sed --follow-symlinks now works again for stdin.
+  [bug introduced in sed-4.2.2]
+
 ** Feature removal
 
   The "L" command (format a paragraph like the fmt(1) command would)
diff --git a/sed/execute.c b/sed/execute.c
index 49cfb45..de2dc4e 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -549,6 +549,7 @@ open_next_file(const char *name, struct input *input)
 {
   buffer.length = 0;
 
+  input->in_file_name = name;
   if (name[0] == '-' && name[1] == '\0')
     {
       if (in_place_extension)
@@ -562,22 +563,23 @@ open_next_file(const char *name, struct input *input)
       input->fp = stdin;
 #endif
     }
-  else if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
+  else
     {
-      const char *ptr = strerror(errno);
-      fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
-      input->read_fn = read_always_fail; /* a redundancy */
-      ++input->bad_count;
-      return;
+      if (follow_symlinks)
+        input->in_file_name = follow_symlink (name);
+
+      if ( ! (input->fp = ck_fopen(name, read_mode, false)) )
+        {
+          const char *ptr = strerror(errno);
+          fprintf(stderr, _("%s: can't read %s: %s\n"), myname, name, ptr);
+          input->read_fn = read_always_fail; /* a redundancy */
+          ++input->bad_count;
+          return;
+        }
     }
 
   input->read_fn = read_file_line;
 
-  if (follow_symlinks)
-    input->in_file_name = follow_symlink (name);
-  else
-    input->in_file_name = name;
-
   if (in_place_extension)
     {
       int input_fd;
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index bfffda0..9bd7465 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -6,6 +6,7 @@ SH_LOG_COMPILER = $(SHELL)
 # Put new, init.sh-using tests here, so that each name
 # is listed in only one place.
 T =			\
+  follow-symlinks-stdin.sh \
   help-version.sh	\
   in-place-hyphen.sh	\
   invalid-mb-seq-UMR.sh	\
diff --git a/testsuite/follow-symlinks-stdin.sh b/testsuite/follow-symlinks-stdin.sh
new file mode 100644
index 0000000..e7cd3b2
--- /dev/null
+++ b/testsuite/follow-symlinks-stdin.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Verify that --follow-symlinks does not break reading from stdin.
+
+# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
+. "${srcdir=.}/init.sh"; path_prepend_ ../sed
+print_ver_ sed
+
+echo "dbc" > exp-out || framework_failure_
+
+fail=0
+echo "abc" | sed --follow-symlinks 's/a/d/' > out 2> err || fail=1
+
+compare exp-out out || fail=1
+compare /dev/null err || fail=1
+
+Exit $fail
-- 
2.4.5

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec <at> suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76




Information forwarded to bug-sed <at> gnu.org:
bug#20795; Package sed. (Thu, 16 Jul 2015 04:47:01 GMT) Full text and rfc822 format available.

Message #11 received at 20795 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Stanislav Brabec <sbrabec <at> suse.com>
Cc: 20795 <at> debbugs.gnu.org
Subject: Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on
 stdin
Date: Wed, 15 Jul 2015 21:45:42 -0700
[Message part 1 (text/plain, inline)]
On Mon, Jul 13, 2015 at 1:59 PM, Stanislav Brabec <sbrabec <at> suse.com> wrote:
> When reading from stdin, --follow-symlinks causes failure since
> v4.2.1-13-g84066bf:
> echo abc | sed --follow-symlinks s/a/d/
> sed: cannot stat -: No such file or directory
>
> Never call follow_symlink("-") to prevent this problem.
> http://bugs.gnu.org/20795

Thank you for the patch.
I've made only a few small changes.
E.g., I added the ChangeLog-style commit log we require,
adjusting wording in a few places, and I removed some
useless quotes in the new test file.

Just in case, I'll wait for you to review and ack before pushing this.
[0001-sed-fix-follow-symlinks-to-work-when-reading-stdin.patch (text/x-patch, attachment)]

Information forwarded to bug-sed <at> gnu.org:
bug#20795; Package sed. (Mon, 20 Jul 2015 13:45:02 GMT) Full text and rfc822 format available.

Message #14 received at 20795 <at> debbugs.gnu.org (full text, mbox):

From: Stanislav Brabec <sbrabec <at> suse.com>
To: Jim Meyering <jim <at> meyering.net>, sbrabec <at> suse.cz
Cc: 20795 <at> debbugs.gnu.org
Subject: Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on
 stdin
Date: Mon, 20 Jul 2015 15:44:28 +0200
On Thu Jun 16, 2015 at 06:45 ANN Jim Meyering wrote:
> On Mon, Jul 13, 2015 at 1:59 PM, Stanislav Brabec <sbrabec <at> suse.com> wrote:
>> When reading from stdin, --follow-symlinks causes failure since
>> v4.2.1-13-g84066bf:
>> echo abc | sed --follow-symlinks s/a/d/
>> sed: cannot stat -: No such file or directory
>>
>> Never call follow_symlink("-") to prevent this problem.
>> http://bugs.gnu.org/20795
>
> Thank you for the patch.
> I've made only a few small changes.
> E.g., I added the ChangeLog-style commit log we require,
> adjusting wording in a few places, and I removed some
> useless quotes in the new test file.
>
> Just in case, I'll wait for you to review and ack before pushing this.
>
ACK, looks OK.

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec <at> suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76




Reply sent to Jim Meyering <jim <at> meyering.net>:
You have taken responsibility. (Mon, 20 Jul 2015 14:07:02 GMT) Full text and rfc822 format available.

Notification sent to Stanislav Brabec <sbrabec <at> suse.com>:
bug acknowledged by developer. (Mon, 20 Jul 2015 14:07:02 GMT) Full text and rfc822 format available.

Message #19 received at 20795-done <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Stanislav Brabec <sbrabec <at> suse.com>
Cc: sbrabec <at> suse.cz, 20795-done <at> debbugs.gnu.org
Subject: Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on
 stdin
Date: Mon, 20 Jul 2015 07:06:23 -0700
On Mon, Jul 20, 2015 at 6:44 AM, Stanislav Brabec <sbrabec <at> suse.com> wrote:
> On Thu Jun 16, 2015 at 06:45 ANN Jim Meyering wrote:
>>
>> On Mon, Jul 13, 2015 at 1:59 PM, Stanislav Brabec <sbrabec <at> suse.com>
>> wrote:
>>>
>>> When reading from stdin, --follow-symlinks causes failure since
>>> v4.2.1-13-g84066bf:
>>> echo abc | sed --follow-symlinks s/a/d/
>>> sed: cannot stat -: No such file or directory
>>>
>>> Never call follow_symlink("-") to prevent this problem.
>>> http://bugs.gnu.org/20795
>>
>>
>> Thank you for the patch.
>> I've made only a few small changes.
>> E.g., I added the ChangeLog-style commit log we require,
>> adjusting wording in a few places, and I removed some
>> useless quotes in the new test file.
>>
>> Just in case, I'll wait for you to review and ack before pushing this.
>>
> ACK, looks OK.

Pushed.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 18 Aug 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 246 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.