This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lseek() SEEK_SET pos may not be negative
authorJarkko Hietaniemi <jhi@iki.fi>
Fri, 26 Jun 2015 12:03:14 +0000 (08:03 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 27 Jun 2015 03:09:44 +0000 (23:09 -0400)
Coverity CID 104832

doio.c

diff --git a/doio.c b/doio.c
index 4500732..ecfe3db 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1206,7 +1206,10 @@ Perl_do_sysseek(pTHX_ GV *gv, Off_t pos, int whence)
 
     if (io && (fp = IoIFP(io))) {
         int fd = PerlIO_fileno(fp);
-        if (fd >= 0) {
+        if (fd < 0 || (whence == SEEK_SET && pos < 0)) {
+            SETERRNO(EINVAL,LIB_INVARG);
+            return -1;
+        } else {
             return PerlLIO_lseek(fd, pos, whence);
         }
     }