From: Stefan Fritsch Date: Sat, 21 May 2011 20:34:05 +0000 (+0000) Subject: Add ap_regexec_len() function that works with non-null-terminated X-Git-Tag: 2.3.13~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63366c900bff1d469323edc6ebaaf818b8f346d1;p=thirdparty%2Fapache%2Fhttpd.git Add ap_regexec_len() function that works with non-null-terminated strings. PR: 51231 Submitted by: Yehezkel Horowitz , Stefan Fritsch git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125802 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 744e92c09d8..6ec34cbb60d 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.13 + *) core: Add ap_regexec_len() function that works with non-null-terminated + strings. PR 51231. [Yehezkel Horowitz ] + *) mod_authnz_ldap: If the LDAP server returns constraint violation, don't treat this as an error but as "auth denied". [Stefan Fritsch] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 394d65abf20..4d4f612c7c3 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -322,6 +322,7 @@ * 20110329.2 (2.3.12-dev) Add child_status and end_generation hooks. * 20110329.3 (2.3.12-dev) Add format field to ap_errorlog_info. * 20110329.4 (2.3.13-dev) bgrowth and max_balancers to proxy_server_conf. + * 20110329.5 (2.3.13-dev) Add ap_regexec_len() */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -329,7 +330,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20110329 #endif -#define MODULE_MAGIC_NUMBER_MINOR 4 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 5 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/ap_regex.h b/include/ap_regex.h index 9882c3fc5f4..cc52078cba1 100644 --- a/include/ap_regex.h +++ b/include/ap_regex.h @@ -123,6 +123,22 @@ AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags); AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string, apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags); +/** + * Match a string with given length against a pre-compiled regex. The string + * does not need to be NUL-terminated. + * @param preg The pre-compiled regex + * @param buff The string to match + * @param len Length of the string to match + * @param nmatch Provide information regarding the location of any matches + * @param pmatch Provide information regarding the location of any matches + * @param eflags Bitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, + * other flags are ignored) + * @return 0 for successful match, AP_REG_NOMATCH otherwise + */ +AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff, + apr_size_t len, apr_size_t nmatch, + ap_regmatch_t *pmatch, int eflags); + /** * Return the error code returned by regcomp or regexec into error messages * @param errcode the error code returned by regexec or regcomp diff --git a/server/util_pcre.c b/server/util_pcre.c index f40d45cbb25..0589e1ada04 100644 --- a/server/util_pcre.c +++ b/server/util_pcre.c @@ -152,11 +152,17 @@ the POSIX structures as was done in earlier releases when PCRE needed only 2 ints. However, if the number of possible capturing brackets is small, use a block of store on the stack, to reduce the use of malloc/free. The threshold is in a macro that can be changed at configure time. */ - AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string, - apr_size_t nmatch, ap_regmatch_t pmatch[], + apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags) { +return ap_regexec_len(preg, string, strlen(string), nmatch, pmatch, eflags); +} + +AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff, + apr_size_t len, apr_size_t nmatch, + ap_regmatch_t *pmatch, int eflags) +{ int rc; int options = 0; int *ovector = NULL; @@ -182,7 +188,7 @@ if (nmatch > 0) } } -rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string), +rc = pcre_exec((const pcre *)preg->re_pcre, NULL, buff, (int)len, 0, options, ovector, nmatch * 3); if (rc == 0) rc = nmatch; /* All captured slots were filled in */