]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add ap_regexec_len() function that works with non-null-terminated
authorStefan Fritsch <sf@apache.org>
Sat, 21 May 2011 20:34:05 +0000 (20:34 +0000)
committerStefan Fritsch <sf@apache.org>
Sat, 21 May 2011 20:34:05 +0000 (20:34 +0000)
strings.

PR: 51231
Submitted by: Yehezkel Horowitz <horowity checkpoint com>, Stefan Fritsch

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1125802 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/ap_mmn.h
include/ap_regex.h
server/util_pcre.c

diff --git a/CHANGES b/CHANGES
index 744e92c09d89560a26e2123f53394ae2a32cb675..6ec34cbb60d18bce37d7bc66b7feac8e7f39e814 100644 (file)
--- 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 <horowity checkpoint com>]
+
   *) mod_authnz_ldap: If the LDAP server returns constraint violation,
      don't treat this as an error but as "auth denied". [Stefan Fritsch]
 
index 394d65abf2020161f1734d0d3aea844149014ad1..4d4f612c7c39b7cbe3469519914d745529540386 100644 (file)
  * 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" */
 #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
index 9882c3fc5f480fa71f96db77a6aa175d722f6a06..cc52078cba1b6c7bf193f347939badcbeca17c60 100644 (file)
@@ -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
index f40d45cbb255c281ffc9b71832015077980e9fb7..0589e1ada04cd35319de81a2355d069f4a0ab14a 100644 (file)
@@ -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 */