blob: 90a5115564acfc2a55b2a0d282539f6fadaad86c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
From b99395ebf70eadb248da0ecf913eea0236eceea1 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
Date: Wed, 16 Nov 2022 11:52:29 +0900
Subject: [PATCH] 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
66957 2398 1552 70907 114fb busybox_old
67004 2398 1552 70954 1152a busybox_unstripped
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
Upstream patch:
http://lists.busybox.net/pipermail/busybox/2022-November/089967.html
editors/sed.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/editors/sed.c b/editors/sed.c
index 32a4b61f6d4c..be709eef3a9c 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1639,6 +1639,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.35.1
|