Bug 620401 - sed overwrites symlinks
sed overwrites symlinks
Status: CLOSED NEXTRELEASE
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: doc-Migration_Guide (Show other bugs)
6.0
All Linux
high Severity high
: rc
: ---
Assigned To: Laura Bailey
ecs-bugs
: Documentation, Regression
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-02 08:48 EDT by Miroslav Vadkerti
Modified: 2013-02-05 18:55 EST (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-08-03 17:23:35 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Miroslav Vadkerti 2010-08-02 08:48:02 EDT
Description of problem:
sed overwrites symlinks and creates ordinary file instead. This is a Regression of bz#189016.

Version-Release number of selected component (if applicable):
sed-4.2.1-5.el6

How reproducible:
100%

Steps to Reproduce:
1. touch src
2. ln -s src lnk
3. sed -i 's.o.n.g' lnk
  
Actual results:
lnk is overwritten

Expected results:
lnk not overwritten

Additional info:
Comment 2 Paolo Bonzini 2010-08-02 09:28:57 EDT
This change was done in Fedora 11 and is by design. 

RHEL 3 included this change without even looking at the manual or contacting upstream.  In doing so it deviated unnecessarily from what is documented in its own "info sed", from upstream, from basically all other Linux distros, and also from "perl -i" behavior.

The implementation was also bad, since there are bugs in symlink following in RHEL5 -- bug #490473 -- while realpath(3) could have been used much more simply...

RHEL6 sed provides --follow-symlinks which achieves this behavior.

I suggest documenting it in the release notes.
Comment 3 Paolo Bonzini 2010-08-02 09:32:22 EDT
From the sed manual of RHEL6

`-i' clobbers read-only files
     In short, `sed -i' will let you delete the contents of a read-only
     file, and in general the `-i' option (*note Invocation: Invoking
     sed.) lets you clobber protected files.  This is not a bug, but
     rather a consequence of how the Unix filesystem works.

     The permissions on a file say what can happen to the data in that
     file, while the permissions on a directory say what can happen to
     the list of files in that directory.  `sed -i' will not ever open
     for writing  a file that is already on disk.  Rather, it will work
     on a temporary file that is finally renamed to the original name:
     if you rename or delete files, you're actually modifying the
     contents of the directory, so the operation depends on the
     permissions of the directory, not of the file.  For this same
     reason, `sed' does not let you use `-i' on a writeable file in a
     read-only directory, and will break hard or symbolic links when
     `-i' is used on such a file.


Everything except "and will break hard or symbolic links when `-i' is used on such a file" is present also in RHEL5 (however it could be inferred from the description, which says it is renaming a temporary file to the original name).
Comment 4 Paolo Bonzini 2010-08-02 09:38:10 EDT
See also http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=339793 (comments #31 to #51 -- that's just five comments actually).
Comment 5 Denise Dumas 2010-08-02 16:26:21 EDT
Scott, Migration Guide text in comment 3
Comment 8 Denise Dumas 2010-08-03 08:51:05 EDT
Scott, this is a Migration Guide blocker for 6.0
Comment 9 Scott Radvan 2010-08-03 17:23:35 EDT
Note added to Migration Guide. Changes will appear on next publish.

Note You need to log in before you can comment on or make changes to this bug.