diff options
author | Dominique Martinet <dominique.martinet@atmark-techno.com> | 2023-09-19 17:11:02 +0900 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-01-02 00:58:56 +0100 |
commit | 5dc9ece3b9e87af0dcb01449821ac827391ac116 (patch) | |
tree | d793f9ebff0316209d063aea9ff3e7d352949520 | |
parent | 1cac2585217f830d29f7e9d2a1226d55c80886b6 (diff) | |
download | busybox-w32-5dc9ece3b9e87af0dcb01449821ac827391ac116.tar.gz busybox-w32-5dc9ece3b9e87af0dcb01449821ac827391ac116.tar.bz2 busybox-w32-5dc9ece3b9e87af0dcb01449821ac827391ac116.zip |
sed: check errors writing file with sed -i
sed would currently not error if write failed when modifying a file.
This can be reproduced with the following 'script':
$ sudo mount -t tmpfs tmpfs -o size=1M /tmp/m
$ sudo chmod 777 /tmp/m
$ echo foo > /tmp/m/foo
$ dd if=/dev/zero of=/tmp/m/fill bs=4k
dd: error writing '/tmp/m/fill': No space left on device
256+0 records in
255+0 records out
1044480 bytes (1.0 MB, 1020 KiB) copied, 0.00234567 s, 445 MB/s
$ busybox sed -i -e 's/.*/bar/' /tmp/m/foo
$ echo $?
0
$ cat /tmp/m/foo
<empty>
new behaviour:
$ echo foo > /tmp/m/foo
$ ./busybox sed -i -e 's/.*/bar/' /tmp/m/foo
sed: write error
$ echo $?
4
$ cat /tmp/m/foo
foo
function old new delta
sed_main 754 801 +47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 47/0) Total: 47 bytes
text data bss dec hex filename
75727 2510 1552 79789 137ad busybox_old
75774 2510 1552 79836 137dc busybox_unstripped
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/sed.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/editors/sed.c b/editors/sed.c index 00dde60be..6179c5e80 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -1648,6 +1648,11 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1648 | fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid); | 1648 | fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid); |
1649 | 1649 | ||
1650 | process_files(); | 1650 | process_files(); |
1651 | fflush(G.nonstdout); | ||
1652 | if (ferror(G.nonstdout)) { | ||
1653 | xfunc_error_retval = 4; /* It's what gnu sed exits with... */ | ||
1654 | bb_simple_error_msg_and_die(bb_msg_write_error); | ||
1655 | } | ||
1651 | fclose(G.nonstdout); | 1656 | fclose(G.nonstdout); |
1652 | G.nonstdout = stdout; | 1657 | G.nonstdout = stdout; |
1653 | 1658 | ||