Subject: bug#20795: closed (Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on stdin)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 20 Jul 2015 14:07:02 +0000

Your bug report

#20795: [PATCH] Fix behavior of --follow-symlinks on stdin

which was filed against the sed package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
20795: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20795
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#20795: [PATCH][TRY2] Fix behavior of --follow-symlinks on stdin
From: Jim Meyering <[email-masked]>
To: Stanislav Brabec <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Mon, 20 Jul 2015 07:06:23 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On Mon, Jul 20, 2015 at 6:44 AM, Stanislav Brabec <[email-masked]> wrote:
> On Thu Jun 16, 2015 at 06:45 ANN Jim Meyering wrote:
>>
>> On Mon, Jul 13, 2015 at 1:59 PM, Stanislav Brabec <[email-masked]>
>> 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.

Subject: [PATCH] Fix behavior of --follow-symlinks on stdin
From: Stanislav Brabec <[email-masked]>
To: [email-masked]
Date: Fri, 12 Jun 2015 17:30:25 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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 <[email-masked]>
---
 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: [email-masked]
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