This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix thinko in hek_eq_pvn_flags
authorFather Chrysostomos <sprout@cpan.org>
Sat, 24 Sep 2011 13:29:10 +0000 (06:29 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:01:02 +0000 (13:01 -0700)
Doing memEQ(str1, str2, len2) without checking the length
first will cause memEQ("forth","fort"...) to compare equal and
memEQ("fort","forth"...) to read unallocated memory.

This was only a potential future problem, as none of the callers reach
this branch.

hv.c

diff --git a/hv.c b/hv.c
index a5a0f1a..2004d3d 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -2102,7 +2102,7 @@ hek_eq_pvn_flags(pTHX_ const HEK *hek, const char* pv, const I32 pvlen, const U3
                        (const U8*)HEK_KEY(hek), HEK_LEN(hek)) == 0);
     }
     else
-        return ((HEK_KEY(hek) == pv)
+        return HEK_LEN(hek) == pvlen && ((HEK_KEY(hek) == pv)
                     || memEQ(HEK_KEY(hek), pv, pvlen));
 }