Skip Menu |

This queue is for tickets about the IPC-SysV CPAN distribution.

Report information
The Basics
Id: 105416
Status: resolved
Priority: 0/
Queue: IPC-SysV

People
Owner: Nobody in particular
Requestors: JHI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.04
Fixed in: (no value)



Subject: Coverity finding: Argument cannot be negative
SysV.xs: 394 #ifdef HAS_SHM 395 void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; CID 104829: Argument cannot be negative (NEGATIVE_RETURNS) 10. negative_returns: id is passed to a parameter that cannot be negative. 396 void *shm = (void *) shmat(id, caddr, flag); I assume Coverity just wants to see testing against id validity before blindly calling shmat().
Subject: [PATCH] Coverity finding: Argument cannot be negative
On Mon Jun 22 20:14:06 2015, JHI wrote: Show quoted text
> SysV.xs: > > 394 #ifdef HAS_SHM > 395 void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; > > CID 104829: Argument cannot be negative (NEGATIVE_RETURNS) > 10. negative_returns: id is passed to a parameter that cannot be > negative. > 396 void *shm = (void *) shmat(id, caddr, flag); > > I assume Coverity just wants to see testing against id validity before > blindly calling shmat().
Patch attached.
Subject: 0001-shmat-id-must-be-non-negative.patch
From f00e2dc34488fef060821172908c96151c95b78f Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi <jhi@iki.fi> Date: Thu, 22 Oct 2015 19:36:33 -0400 Subject: [PATCH] shmat id must be non-negative Coverity #104829 --- cpan/IPC-SysV/SysV.xs | 12 ++++++++---- cpan/IPC-SysV/t/ipcsysv.t | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpan/IPC-SysV/SysV.xs b/cpan/IPC-SysV/SysV.xs index c7db50a..121a164 100644 --- a/cpan/IPC-SysV/SysV.xs +++ b/cpan/IPC-SysV/SysV.xs @@ -392,10 +392,14 @@ shmat(id, addr, flag) int flag CODE: #ifdef HAS_SHM - void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; - void *shm = (void *) shmat(id, caddr, flag); - ST(0) = shm == (void *) -1 ? &PL_sv_undef - : sv_2mortal(newSVpvn((char *) &shm, sizeof(void *))); + if (id >= 0) { + void *caddr = SvOK(addr) ? sv2addr(addr) : NULL; + void *shm = (void *) shmat(id, caddr, flag); + ST(0) = shm == (void *) -1 ? &PL_sv_undef + : sv_2mortal(newSVpvn((char *) &shm, sizeof(void *))); + } else { + ST(0) = &PL_sv_undef; + } XSRETURN(1); #else Perl_die(aTHX_ PL_no_func, "shmat"); return; diff --git a/cpan/IPC-SysV/t/ipcsysv.t b/cpan/IPC-SysV/t/ipcsysv.t index 710555e..c7a92ed 100644 --- a/cpan/IPC-SysV/t/ipcsysv.t +++ b/cpan/IPC-SysV/t/ipcsysv.t @@ -24,7 +24,7 @@ elsif ($Config{'d_msg'} ne 'define') { plan(skip_all => '$Config{d_msg} undefined'); } -plan(tests => 38); +plan(tests => 39); # These constants are common to all tests. # Later the sem* tests will import more for themselves. @@ -298,6 +298,8 @@ SKIP: { is(unpack("N", unpack("P4", $addr)), 0xbadc0de5, 'read modified shm by addr'); + is(shmat(-1, undef, 0), undef, 'shmat illegal id fails'); + ok(defined shmdt($addr), 'shmdt'); } -- 2.6.0
Ping.
On Sat Feb 13 21:59:29 2016, JHI wrote: Show quoted text
> Ping.
Sorry for the radio silence. This is now part of IPC-SysV 2.05 which has just entered PAUSE.