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

ext/POSIX/POSIX.xs

index 670d8ec..514b514 100644 (file)
@@ -3210,9 +3210,14 @@ lseek(fd, offset, whence)
        Off_t           offset
        int             whence
     CODE:
        Off_t           offset
        int             whence
     CODE:
-       Off_t pos = PerlLIO_lseek(fd, offset, whence);
-       RETVAL = sizeof(Off_t) > sizeof(IV)
-                ? newSVnv((NV)pos) : newSViv((IV)pos);
+       if (fd >= 0) {
+            Off_t pos = PerlLIO_lseek(fd, offset, whence);
+            RETVAL = sizeof(Off_t) > sizeof(IV)
+              ? newSVnv((NV)pos) : newSViv((IV)pos);
+        } else {
+            SETERRNO(EBADF,RMS_IFI);
+            RETVAL = newSViv(-1);
+        }
     OUTPUT:
        RETVAL
 
     OUTPUT:
        RETVAL