This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Ascertain that the fd for fcntl is not negative
authorJarkko Hietaniemi <jhi@iki.fi>
Thu, 22 Oct 2015 11:36:56 +0000 (07:36 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 24 Oct 2015 00:55:58 +0000 (20:55 -0400)
Coverity id #45354

Since maxsysfd is I32 Coverity cannot prove that being larger than
it means that the fd is non-negative.

doio.c

diff --git a/doio.c b/doio.c
index 5ebb7f1..d95ad9c 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -772,7 +772,7 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname,
        fd = PerlIO_fileno(fp);
     }
 #if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC)
-    if (fd > PL_maxsysfd && fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
+    if (fd >= 0 && fd > PL_maxsysfd && fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
         PerlLIO_close(fd);
         goto say_false;
     }