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.

Full log


View this message in rfc822 format

From: Stanislav Brabec <sbrabec <at> suse.com>
To: 20795 <at> debbugs.gnu.org
Subject: bug#20795: [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




This bug report was last modified 9 years and 304 days ago.

Previous Next


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