summaryrefslogtreecommitdiff
path: root/coreutils/printf.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-07-25 13:34:05 +0000
committerDenis Vlasenko2008-07-25 13:34:05 +0000
commit6a0ad2506116f4ddc3f9f617a90ba04a57eeef88 (patch)
treebb40f8aa8574d4aef536cfe930517c0bf44e28a7 /coreutils/printf.c
parent0f99d49ae680e675809428deace3c4fe839d323c (diff)
downloadbusybox-6a0ad2506116f4ddc3f9f617a90ba04a57eeef88.zip
busybox-6a0ad2506116f4ddc3f9f617a90ba04a57eeef88.tar.gz
ash: dont allow e.g. exec <&10 to attach to stript's fd!
function old new delta is_hidden_fd - 61 +61 redirect 1135 1164 +29 popstring 134 140 +6 printf_main 635 637 +2 evalvar 1374 1376 +2 echo_main 294 296 +2 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/0 up/down: 102/0) Total: 102 bytes
Diffstat (limited to 'coreutils/printf.c')
-rw-r--r--coreutils/printf.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/coreutils/printf.c b/coreutils/printf.c
index 72acbc7..76524f7 100644
--- a/coreutils/printf.c
+++ b/coreutils/printf.c
@@ -348,8 +348,11 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
* even if libc receives EBADF on write attempts, it feels determined
* to output data no matter what. So it will try later,
* and possibly will clobber future output. Not good. */
- if (dup2(1, 1) != 1)
- return -1;
+// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
+ if (fcntl(1, F_GETFL) == -1)
+ return 1; /* match coreutils 6.10 (sans error msg to stderr) */
+ //if (dup2(1, 1) != 1) - old way
+ // return 1;
/* bash builtin errors out on "printf '-%s-\n' foo",
* coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".