This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tcdrain fd can be bad.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 23 Jun 2015 11:28:57 +0000 (07:28 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 27 Jun 2015 03:09:41 +0000 (23:09 -0400)
Coverity CID 104838.

ext/POSIX/POSIX.xs

index 83f6452..ce4c12c 100644 (file)
@@ -3499,8 +3499,13 @@ tcdrain(fd)
        close = 1
        dup = 2
     CODE:
-       RETVAL = ix == 1 ? close(fd)
-           : (ix < 1 ? tcdrain(fd) : dup(fd));
+       if (fd >= 0) {
+           RETVAL = ix == 1 ? close(fd)
+             : (ix < 1 ? tcdrain(fd) : dup(fd));
+       } else {
+           SETERRNO(EBADF,RMS_IFI);
+           RETVAL = -1;
+       }
     OUTPUT:
        RETVAL