avoid calling memset with a negative count
authorAndy Dougherty <doughera@lafayette.edu>
Thu, 27 Sep 2012 13:52:18 +0000 (09:52 -0400)
committerRicardo Signes <rjbs@cpan.org>
Wed, 17 Oct 2012 15:47:58 +0000 (11:47 -0400)
Poorly written perl code that allows an attacker to specify the count to
perl's 'x' string repeat operator can already cause a memory exhaustion
denial-of-service attack. A flaw in versions of perl before 5.15.5 can
escalate that into a heap buffer overrun; coupled with versions of glibc
before 2.16, it possibly allows the execution of arbitrary code.

The flaw addressed to this commit has been assigned identifier
CVE-2012-5195.

util.c

diff --git a/util.c b/util.c
index 8bd2094..2633034 100644 (file)
--- a/util.c
+++ b/util.c
@@ -3256,6 +3256,9 @@ Perl_repeatcpy(register char *to, register const char *from, I32 len, register I
 {
     PERL_ARGS_ASSERT_REPEATCPY;
 
+    if (count < 0)
+       Perl_croak_nocontext("%s",PL_memory_wrap);
+
     if (len == 1)
        memset(to, *from, count);
     else if (count) {