From 6a0ad2506116f4ddc3f9f617a90ba04a57eeef88 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Fri, 25 Jul 2008 13:34:05 +0000 Subject: 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 --- coreutils/echo.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'coreutils/echo.c') 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) * 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; arg = *++argv; if (!arg) @@ -58,8 +61,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv) char eflag = 0; /* We must check that stdout is not closed. */ - if (dup2(1, 1) != 1) - return -1; + if (fcntl(1, F_GETFL) == -1) + return 1; while (1) { arg = *++argv; -- cgit v1.2.3