sed/sed-follow-symlinks-hyphen.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

52 lines
2.0 KiB
Diff

This is a backport of the fix itself.
From c033bdee411128dfebfea1974d1ee3c1d9eac572 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sat, 20 Jun 2015 07:38:49 -0700
Subject: [PATCH] sed -i: do not treat "-" as a file name
Most GNU utilities treat "-" as standard input, sed itself does that --
in most contexts. However, since the addition of support for
--in-place (-i) in sed-4.0, sed -i has treated a "-" argument as a
file name, i.e., like ./-. Now, that usage evokes a diagnostic:
$ sed -i s/a/b/ -
sed: couldn't edit -: is a terminal
If you require the old behavior, specify the file name as "./-".
Prompted by the report/patch from Stanislav Brabec in
http://bugs.gnu.org/20796 to document the strangely
inconsistent legacy behavior.
* sed/execute.c (open_next_file): Call panic before
even attempting to operate on the file descriptor.
* testsuite/in-place-hyphen.sh: New file. Test for this.
* testsuite/Makefile.am (T): Add it.
* NEWS (Feature removal): Mention it. Admittedly, the old behavior
feels more like a misfeature.
---
NEWS | 3 +++
sed/execute.c | 5 ++++-
testsuite/Makefile.am | 1 +
testsuite/in-place-hyphen.sh | 29 +++++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 1 deletion(-)
create mode 100755 testsuite/in-place-hyphen.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,8 +580,11 @@ open_next_file(name, input)
{
buffer.length = 0;
- if (name[0] == '-' && name[1] == '\0' && !in_place_extension)
+ if (name[0] == '-' && name[1] == '\0')
{
+ if (in_place_extension)
+ panic(_("couldn't edit %s: is a terminal"), name);
+
clearerr(stdin); /* clear any stale EOF indication */
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(MSDOS) || defined(__EMX__)
input->fp = ck_fdopen (fileno (stdin), "stdin", read_mode, false);