This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
shmat id can be invalid.
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 23 Jun 2015 11:30:58 +0000 (07:30 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Sat, 27 Jun 2015 03:09:43 +0000 (23:09 -0400)
Coverity CID 104852.

doio.c

diff --git a/doio.c b/doio.c
index 2dfd5f4..4500732 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -2467,7 +2467,12 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
        SETERRNO(EFAULT,SS_ACCVIO);             /* can't do as caller requested */
        return -1;
     }
-    shm = (char *)shmat(id, NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0);
+    if (id >= 0) {
+        shm = (char *)shmat(id, NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0);
+    } else {
+        SETERRNO(EINVAL,LIB_INVARG);
+        return -1;
+    }
     if (shm == (char *)-1)     /* I hate System V IPC, I really do */
        return -1;
     if (optype == OP_SHMREAD) {