From: Joe Orton Date: Fri, 19 Aug 2005 15:56:36 +0000 (+0000) Subject: Backport patch from pcre 6.2 to fix integer overflows in quantifier X-Git-Tag: 2.1.7~5^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fdf7c8ac42b917a150fe94d9bf8e00c24ef6973;p=apache Backport patch from pcre 6.2 to fix integer overflows in quantifier parsing: * srclib/pcre/pcre.c (read_repeat_counts): Check for integer overflow. Obtained from: pcre 6.2 upstream git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@233493 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 8a6571b44f..81d92e1ce1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ -*- coding: utf-8 -*- Changes with Apache 2.3.0 + *) SECURITY: CAN-2005-2491 (cve.mitre.org): + Fix integer overflows in PCRE in quantifier parsing which could + be triggered by a local user through use of a carefully-crafted + regex in an .htaccess file. [Philip Hazel] + *) mod_proxy/mod_proxy_balancer: Provide a simple, functional interface to add additional balancer lb selection methods without requiring code changes to mod_proxy/mod_proxy_balancer; diff --git a/srclib/pcre/pcre.c b/srclib/pcre/pcre.c index dc013faf02..4936323a3b 100644 --- a/srclib/pcre/pcre.c +++ b/srclib/pcre/pcre.c @@ -1247,7 +1247,18 @@ read_repeat_counts(const uschar *p, int *minp, int *maxp, const char **errorptr) int min = 0; int max = -1; +/* Read the minimum value and do a paranoid check: a negative value indicates +an integer overflow. */ + while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0'; +if (min < 0 || min > 65535) + { + *errorptr = ERR5; + return p; + } + +/* Read the maximum value if there is one, and again do a paranoid on its size. +Also, max must not be less than min. */ if (*p == '}') max = min; else { @@ -1255,6 +1266,11 @@ if (*p == '}') max = min; else { max = 0; while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0'; + if (max < 0 || max > 65535) + { + *errorptr = ERR5; + return p; + } if (max < min) { *errorptr = ERR4; @@ -1263,16 +1279,11 @@ if (*p == '}') max = min; else } } -/* Do paranoid checks, then fill in the required variables, and pass back the -pointer to the terminating '}'. */ +/* Fill in the required variables, and pass back the pointer to the terminating +'}'. */ -if (min > 65535 || max > 65535) - *errorptr = ERR5; -else - { - *minp = min; - *maxp = max; - } +*minp = min; +*maxp = max; return p; }