Date: Tue, 27 Aug 2013 21:47:01 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r254977 - head/lib/libc/gen Message-ID: <201308272147.r7RLl165082311@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Tue Aug 27 21:47:01 2013 New Revision: 254977 URL: http://svnweb.freebsd.org/changeset/base/254977 Log: wordexp(): Avoid leaking the pipe file descriptors to a parallel fork/exec. This uses the new pipe2() system call added on May 1 (r250159). Modified: head/lib/libc/gen/wordexp.c Modified: head/lib/libc/gen/wordexp.c ============================================================================== --- head/lib/libc/gen/wordexp.c Tue Aug 27 21:29:21 2013 (r254976) +++ head/lib/libc/gen/wordexp.c Tue Aug 27 21:47:01 2013 (r254977) @@ -121,7 +121,7 @@ we_askshell(const char *words, wordexp_t serrno = errno; - if (pipe(pdes) < 0) + if (pipe2(pdes, O_CLOEXEC) < 0) return (WRDE_NOSPACE); /* XXX */ (void)sigemptyset(&newsigblock); (void)sigaddset(&newsigblock, SIGCHLD); @@ -140,10 +140,10 @@ we_askshell(const char *words, wordexp_t * builtin on `words'. */ (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); - _close(pdes[0]); - if (_dup2(pdes[1], STDOUT_FILENO) < 0) + if ((pdes[1] != STDOUT_FILENO ? + _dup2(pdes[1], STDOUT_FILENO) : + _fcntl(pdes[1], F_SETFD, 0)) < 0) _exit(1); - _close(pdes[1]); execl(_PATH_BSHELL, "sh", flags & WRDE_UNDEF ? "-u" : "+u", "-c", "eval \"$1\";eval \"wordexp $2\"", "", flags & WRDE_SHOWERR ? "" : "exec 2>/dev/null", words,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308272147.r7RLl165082311>