Skip Menu |

This queue is for tickets about the Socket CPAN distribution.

Report information
The Basics
Id: 111707
Status: resolved
Priority: 0/
Queue: Socket

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

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



Subject: [PATCH] Coverity finding: tests in wrong order
In Socket.xs an array size test is *after* the array access. Patch attached.
Subject: 0001-The-test-for-maxlen-needs-to-be-before-the-array-acc.patch
From cdf48c5d54c509fde100aaad32aa7644fcc5ff6b Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi <jhi@iki.fi> Date: Wed, 3 Feb 2016 08:26:11 -0500 Subject: [PATCH] The test for maxlen needs to be before the array access. Coverity CID 135025 Out-of-bounds READ (OVERRUN) --- cpan/Socket/Socket.xs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpan/Socket/Socket.xs b/cpan/Socket/Socket.xs index 52df483..2e2d7be 100644 --- a/cpan/Socket/Socket.xs +++ b/cpan/Socket/Socket.xs @@ -861,8 +861,8 @@ unpack_sockaddr_un(sun_sv) # else const int maxlen = (int)sizeof(addr.sun_path); # endif - for (addr_len = 0; addr.sun_path[addr_len] - && addr_len < maxlen; addr_len++); + for (addr_len = 0; addr_len < maxlen && + addr.sun_path[addr_len]; addr_len++); } ST(0) = sv_2mortal(newSVpvn(addr.sun_path, addr_len)); -- 2.7.0
On Wed Feb 03 08:31:05 2016, JHI wrote: Show quoted text
> In Socket.xs an array size test is *after* the array access. Patch > attached.
Since this is potential crasher, went ahead and pushed to blead as http://perl5.git.perl.org/perl.git/commitdiff/2d703bea55021a04c1b7a7b0abfe231ebd104d13
I've never really liked side-effecting for loops with empty bodies like that; they look too subtle to read. I've rewritten it now as a while loop and at the same time fixed the test order. New patch attached, which will be version 2.022 -- Paul Evans
Subject: rt111707.patch
=== modified file 'Socket.xs' --- Socket.xs 2015-11-18 17:06:20 +0000 +++ Socket.xs 2016-03-09 23:39:21 +0000 @@ -878,7 +878,7 @@ struct sockaddr_un addr; STRLEN sockaddrlen; char * sun_ad = SvPVbyte(sun_sv,sockaddrlen); - int addr_len; + int addr_len = 0; # if defined(__linux__) || defined(HAS_SOCKADDR_SA_LEN) /* On Linux or *BSD sockaddrlen on sockets returned by accept, recvfrom, getpeername and getsockname is not equal to sizeof(addr). */ @@ -920,8 +920,8 @@ # else const int maxlen = (int)sizeof(addr.sun_path); # endif - for (addr_len = 0; addr.sun_path[addr_len] - && addr_len < maxlen; addr_len++); + while (addr_len < maxlen && addr.sun_path[addr_len]) + addr_len++; } ST(0) = sv_2mortal(newSVpvn(addr.sun_path, addr_len));
On Wed Mar 09 18:40:55 2016, PEVANS wrote: Show quoted text
> New patch attached, which will be version 2.022
This patch is also included in the cperl variant of Socket, uploaded as RURBAN/Socket-2.021_02.tar.gz -- Reini Urban
Released in 2.022 -- Paul Evans