Bug 7484

Summary: sed -i on missing file creates output with random permissions
Product: Busybox Reporter: Nick Gasson <nick.gasson>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.22.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Attachments: Patch to sed.c to fix this

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!