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