]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Improve handling of maxlen = APR_SIZE_MAX, noticed by Jim.
authorStefan Fritsch <sf@apache.org>
Thu, 27 Oct 2011 20:15:36 +0000 (20:15 +0000)
committerStefan Fritsch <sf@apache.org>
Thu, 27 Oct 2011 20:15:36 +0000 (20:15 +0000)
Use apr_pregsub_ex() and maxlen = 0 for unlimited in mod_substitute.

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

include/httpd.h
include/util_varbuf.h
modules/filters/mod_substitute.c
server/util.c

index f6b372eb539fa13e2edbee5a4a030a54aef07da4..28c9eb179e3e4093061d4b749aa70eafab0ab9cf 100644 (file)
@@ -1799,7 +1799,7 @@ AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *sour
  * @param source The string that was originally matched to the regex
  * @param nmatch the nmatch returned from ap_pregex
  * @param pmatch the pmatch array returned from ap_pregex
- * @param maxlen the maximum string length to return
+ * @param maxlen the maximum string length to return, 0 for unlimited
  * @return The substituted string, or NULL on error
  */
 AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result,
index 64637f3b4c4d87e3ee3476e9d6a56634052d9856..28fb8672030c306efd6332429f8787b045838858 100644 (file)
@@ -135,7 +135,7 @@ AP_DECLARE(char *) ap_varbuf_pdup(apr_pool_t *p, struct ap_varbuf *vb,
  * @param source The string that was originally matched to the regex
  * @param nmatch the nmatch returned from ap_pregex
  * @param pmatch the pmatch array returned from ap_pregex
- * @param maxlen the maximum string length to append to vb
+ * @param maxlen the maximum string length to append to vb, 0 for unlimited
  * @return APR_SUCCESS if successful
  * @note Just like ap_pregsub(), this function does not copy the part of
  *       *source before the matching part (i.e. the first pmatch[0].rm_so
index 3a59caa99e2382e9e2eef75cffaaab05421c89bd..bd0dafd70e6754b7c58aa3a23edbf81ca491922d 100644 (file)
@@ -98,7 +98,6 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb,
     apr_size_t bytes;
     apr_size_t len;
     const char *buff;
-    const char *repl;
     struct ap_varbuf vb;
     apr_bucket *b;
     apr_bucket *tmp_b;
@@ -135,6 +134,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb,
                 int have_match = 0;
                 vb.strlen = 0;
                 if (script->pattern) {
+                    const char *repl;
                     while ((repl = apr_strmatch(script->pattern, buff, bytes)))
                     {
                         have_match = 1;
@@ -187,6 +187,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb,
                 else if (script->regexp) {
                     int left = bytes;
                     const char *pos = buff;
+                    char *repl;
                     while (!ap_regexec_len(script->regexp, pos, left,
                                        AP_MAX_REG_MATCH, regm, 0)) {
                         have_match = 1;
@@ -196,12 +197,11 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb,
                                 ap_varbuf_strmemcat(&vb, pos, regm[0].rm_so);
                             /* add replacement string */
                             ap_varbuf_regsub(&vb, script->replacement, pos,
-                                             AP_MAX_REG_MATCH, regm,
-                                             APR_SIZE_MAX);
+                                             AP_MAX_REG_MATCH, regm, 0);
                         }
                         else {
-                            repl = ap_pregsub(pool, script->replacement, pos,
-                                              AP_MAX_REG_MATCH, regm);
+                            ap_pregsub_ex(pool, &repl, script->replacement, pos,
+                                              AP_MAX_REG_MATCH, regm, 0);
                             len = (apr_size_t) (regm[0].rm_eo - regm[0].rm_so);
                             SEDRMPATBCKT(b, regm[0].rm_so, tmp_b, len);
                             tmp_b = apr_bucket_transient_create(repl,
index 0f772e6305ca971ac2e69031c222a2242a16c976..abd7a10e427554c7f1f4417dc474c144c1371ff8 100644 (file)
@@ -386,7 +386,7 @@ static apr_status_t regsub_core(apr_pool_t *p, char **result,
         return APR_EINVAL;
     if (!nmatch || nmatch>AP_MAX_REG_MATCH) {
         len = strlen(src);
-        if (maxlen > 0 && len > maxlen)
+        if (maxlen > 0 && len >= maxlen)
             return APR_ENOMEM;
         if (!vb) {
             *result = apr_pstrmemdup(p, src, len);
@@ -416,7 +416,7 @@ static apr_status_t regsub_core(apr_pool_t *p, char **result,
 
     }
 
-    if (len > maxlen && maxlen > 0)
+    if (len >= maxlen && maxlen > 0)
         return APR_ENOMEM;
 
     if (!vb) {