summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko2014-10-05 02:44:34 +0200
committerDenys Vlasenko2014-10-05 02:44:34 +0200
commitcd738711782d5860eeab4e7cefdd1f72dfb83810 (patch)
tree54677a6bd0215a0979b5c6512b805543550624b7 /editors
parentb434ce70696879aad066fff67253e44e5f5b238e (diff)
downloadbusybox-cd738711782d5860eeab4e7cefdd1f72dfb83810.zip
busybox-cd738711782d5860eeab4e7cefdd1f72dfb83810.tar.gz
sed: fix "sed CMD -i nonexistent_file". Closes 7484
function old new delta sed_main 643 676 +33 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/editors/sed.c b/editors/sed.c
index e1b8352..2c64ad5 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1522,12 +1522,16 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
/* -i: process each FILE separately: */
+ if (stat(*argv, &statbuf) != 0) {
+ bb_simple_perror_msg(*argv);
+ G.exitcode = EXIT_FAILURE;
+ G.current_input_file++;
+ continue;
+ }
G.outname = xasprintf("%sXXXXXX", *argv);
nonstdoutfd = xmkstemp(G.outname);
G.nonstdout = xfdopen_for_write(nonstdoutfd);
-
/* Set permissions/owner of output file */
- stat(*argv, &statbuf);
/* chmod'ing AFTER chown would preserve suid/sgid bits,
* but GNU sed 4.2.1 does not preserve them either */
fchmod(nonstdoutfd, statbuf.st_mode);