Bug 7484 - sed -i on missing file creates output with random permissions
Summary: sed -i on missing file creates output with random permissions
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.22.x
Hardware: PC Linux
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-30 14:26 UTC by Nick Gasson
Modified: 2014-10-05 00:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Patch to sed.c to fix this (1.01 KB, patch)
2014-09-30 14:26 UTC, Nick Gasson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Gasson 2014-09-30 14:26:09 UTC
Created attachment 5696 [details]
Patch to sed.c to fix this

On busybox 1.22:

$ rm -f foo.txt; ./busybox sed -i 's/hello/world/' foo.txt ; ls -l foo.txt
sed: foo.txt: No such file or directory
---S--Srwt 1 nick nick 0 Sep 30 15:19 foo.txt

Problem is caused by editors/sed.c not checking the result of fstat() to get the permissions of the input file. It then uses an uninitialised struct stat to set the permissions on the output file.

Patch attached which fixes the issue for us.
Comment 1 Denys Vlasenko 2014-10-05 00:45:19 UTC
Fixed in git, thanks!