From a1b0be3dcba63937b705887299959ab83975eb75 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sun, 27 May 2012 21:40:00 +0000 Subject: [PATCH] Make ap_regcomp() return AP_REG_ESPACE if out of memory. Make ap_pregcomp() abort if out of memory. This raises the minimum PCRE requirement to version 6.0, released in 2005. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1343109 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ configure.in | 5 +++++ server/util.c | 6 ++++-- server/util_pcre.c | 12 ++++++++++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 3cdb5831ea..aa63119be6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) core: Make ap_regcomp() return AP_REG_ESPACE if out of memory. Make + ap_pregcomp() abort if out of memory. This raises the minimum PCRE + requirement to version 6.0. [Stefan Fritsch] + *) apxs: Use LDFLAGS from config_vars.mk in addition to CFLAGS and CPPFLAGS. [Stefan Fritsch] diff --git a/configure.in b/configure.in index 19ebd887d6..ead96cd09a 100644 --- a/configure.in +++ b/configure.in @@ -225,6 +225,11 @@ if test "$PCRE_CONFIG" != "false"; then if $PCRE_CONFIG --version >/dev/null 2>&1; then :; else AC_MSG_ERROR([Did not find pcre-config script at $PCRE_CONFIG]) fi + case `$PCRE_CONFIG --version` in + [[1-5].*]) + AC_MSG_ERROR([Need at least pcre version 6.0]) + ;; + esac AC_MSG_NOTICE([Using external PCRE library from $PCRE_CONFIG]) APR_ADDTO(PCRE_INCLUDES, [`$PCRE_CONFIG --cflags`]) APR_ADDTO(PCRE_LIBS, [`$PCRE_CONFIG --libs`]) diff --git a/server/util.c b/server/util.c index 177f3780fc..5e2f107106 100644 --- a/server/util.c +++ b/server/util.c @@ -273,8 +273,10 @@ AP_DECLARE(ap_regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern, int cflags) { ap_regex_t *preg = apr_palloc(p, sizeof *preg); - - if (ap_regcomp(preg, pattern, cflags)) { + int err = ap_regcomp(preg, pattern, cflags); + if (err) { + if (err == AP_REG_ESPACE) + ap_abort_on_oom(); return NULL; } diff --git a/server/util_pcre.c b/server/util_pcre.c index 2d157c0c10..1e83cad080 100644 --- a/server/util_pcre.c +++ b/server/util_pcre.c @@ -123,6 +123,7 @@ AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags) { const char *errorptr; int erroffset; + int errcode = 0; int options = 0; if ((cflags & AP_REG_ICASE) != 0) @@ -133,11 +134,18 @@ AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags) options |= PCRE_DOTALL; preg->re_pcre = - pcre_compile(pattern, options, &errorptr, &erroffset, NULL); + pcre_compile2(pattern, options, &errcode, &errorptr, &erroffset, NULL); preg->re_erroffset = erroffset; - if (preg->re_pcre == NULL) + if (preg->re_pcre == NULL) { + /* + * There doesn't seem to be constants defined for compile time error + * codes. 21 is "failed to get memory" according to pcreapi(3). + */ + if (errcode == 21) + return AP_REG_ESPACE; return AP_REG_INVARG; + } pcre_fullinfo((const pcre *)preg->re_pcre, NULL, PCRE_INFO_CAPTURECOUNT, &(preg->re_nsub)); -- 2.40.0