From: Jarkko Hietaniemi Date: Tue, 23 Jun 2015 10:58:35 +0000 (-0400) Subject: dup2 fds can be bad. X-Git-Tag: v5.23.1~104 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/6e7b1a261d86fa4754e5d9ee167b6679abdc1cb2?ds=sidebyside dup2 fds can be bad. Coverity CID 104812. --- diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index ce4c12c..bd13d52 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -3193,14 +3193,20 @@ dup2(fd1, fd2) int fd1 int fd2 CODE: + if (fd1 >= 0 && fd2 >= 0) { #ifdef WIN32 - /* RT #98912 - More Microsoft muppetry - failing to actually implemented - the well known documented POSIX behaviour for a POSIX API. - http://msdn.microsoft.com/en-us/library/8syseb29.aspx */ - RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2; + /* RT #98912 - More Microsoft muppetry - failing to + actually implemented the well known documented POSIX + behaviour for a POSIX API. + http://msdn.microsoft.com/en-us/library/8syseb29.aspx */ + RETVAL = dup2(fd1, fd2) == -1 ? -1 : fd2; #else - RETVAL = dup2(fd1, fd2); + RETVAL = dup2(fd1, fd2); #endif + } else { + SETERRNO(EBADF,RMS_IFI); + RETVAL = -1; + } OUTPUT: RETVAL