aboutsummaryrefslogtreecommitdiff
path: root/coreutils/echo.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-25 13:34:05 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-25 13:34:05 +0000
commit6a0ad2506116f4ddc3f9f617a90ba04a57eeef88 (patch)
treebb40f8aa8574d4aef536cfe930517c0bf44e28a7 /coreutils/echo.c
parent0f99d49ae680e675809428deace3c4fe839d323c (diff)
downloadbusybox-w32-6a0ad2506116f4ddc3f9f617a90ba04a57eeef88.tar.gz
busybox-w32-6a0ad2506116f4ddc3f9f617a90ba04a57eeef88.tar.bz2
busybox-w32-6a0ad2506116f4ddc3f9f617a90ba04a57eeef88.zip
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/echo.c')
-rw-r--r--coreutils/echo.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c
index 36cb6b3af..decca095f 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -46,8 +46,11 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
46 * even if libc receives EBADF on write attempts, it feels determined 46 * even if libc receives EBADF on write attempts, it feels determined
47 * to output data no matter what. So it will try later, 47 * to output data no matter what. So it will try later,
48 * and possibly will clobber future output. Not good. */ 48 * and possibly will clobber future output. Not good. */
49 if (dup2(1, 1) != 1) 49// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
50 return -1; 50 if (fcntl(1, F_GETFL) == -1)
51 return 1; /* match coreutils 6.10 (sans error msg to stderr) */
52 //if (dup2(1, 1) != 1) - old way
53 // return 1;
51 54
52 arg = *++argv; 55 arg = *++argv;
53 if (!arg) 56 if (!arg)
@@ -58,8 +61,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
58 char eflag = 0; 61 char eflag = 0;
59 62
60 /* We must check that stdout is not closed. */ 63 /* We must check that stdout is not closed. */
61 if (dup2(1, 1) != 1) 64 if (fcntl(1, F_GETFL) == -1)
62 return -1; 65 return 1;
63 66
64 while (1) { 67 while (1) {
65 arg = *++argv; 68 arg = *++argv;