[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH resend] sed: check errors writing file with sed -i
From: Dominique Martinet <asmadeus () codewreck ! org>
Date: 2023-09-19 8:11:02
Message-ID: 20230919081102.3136547-1-asmadeus () codewreck ! org
[Download RAW message or body]
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
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>
---
Resending this patch again as it doesn't seem to have been applied.
FWIW it's still applied on alpine builds (since Nov last year); would be
great to see this merged so I can forget about it :)
editors/sed.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/editors/sed.c b/editors/sed.c
index 00dde60be329..6179c5e80958 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1648,6 +1648,11 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid);
process_files();
+ fflush(G.nonstdout);
+ if (ferror(G.nonstdout)) {
+ xfunc_error_retval = 4; /* It's what gnu sed exits with... */
+ bb_simple_error_msg_and_die(bb_msg_write_error);
+ }
fclose(G.nonstdout);
G.nonstdout = stdout;
--
2.39.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic