sed/sed-follow-symlinks-stdin.patch
Stanislav Brabec aab5852676 Accepting request 326633 from home:sbrabec:branches:Base:System
- Cherry picking of the most important fixes from the upstream sed
  GIT (not backporting testsuite, as it was completely refactored):
  * Fix y command in the RHS of a y/LHS/RHS/ transliteration
    (sed-y-NUL-RHS.patch).
  * Fix mishandling of overlapping address ranges
    (sed-fix-overlapping-address-ranges.patch).
  * Fix fail to remove a temporary file (sed-temp-delete.patch).
  * Fix behavior of --follow-symlinks when reading from stdin
    (bnc#933029, gnu#20795, sed-follow-symlinks-stdin.patch).
  * Make "sed --follow-symlinks -" consistent with "sed -" again,
    and process stdin instead of ./-
    (bnc#933029#c6, gnu#20796, sed-follow-symlinks-hyphen.patch).

OBS-URL: https://build.opensuse.org/request/show/326633
OBS-URL: https://build.opensuse.org/package/show/Base:System/sed?expand=0&rev=22
2015-08-27 16:10:55 +00:00

75 lines
2.4 KiB
Diff

This is a backport of the fix itself.
From e387009c78fa08aaebf5192a3ceeb04dcfc7781d Mon Sep 17 00:00:00 2001
From: Stanislav Brabec <sbrabec@suse.com>
Date: Mon, 13 Jul 2015 22:59:17 +0200
Subject: [PATCH] sed: fix --follow-symlinks to work when reading stdin
When reading from stdin, use of --follow-symlinks would cause failure:
$ echo abc | sed --follow-symlinks s/a/d/
sed: cannot stat -: No such file or directory
* sed/execute.c (open_next_file): Set input->in_file_name earlier,
so we can rearrange logic to avoid calling follow_symlink("-").
* testsuite/follow-symlinks-stdin.sh: New file.
* testsuite/Makefile.am (T): Add it.
* NEWS (Bug fixes): Mention it.
Bug introduced by commit v4.2.1-13-g84066bf.
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 100755 testsuite/follow-symlinks-stdin.sh
Index: sed-4.2.2/sed/execute.c
===================================================================
--- sed-4.2.2.orig/sed/execute.c
+++ sed-4.2.2/sed/execute.c
@@ -580,6 +580,7 @@ open_next_file(name, input)
{
buffer.length = 0;
+ input->in_file_name = name;
if (name[0] == '-' && name[1] == '\0')
{
if (in_place_extension)
@@ -592,22 +593,23 @@ open_next_file(name, 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;