]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Disable subcaptures the proper way
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Jan 2015 20:31:57 +0000 (15:31 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 5 Jan 2015 01:50:31 +0000 (20:50 -0500)
src/include/regex.h
src/lib/pair.c
src/lib/regex.c
src/main/evaluate.c
src/main/modcall.c
src/main/pair.c
src/main/realms.c

index 16aa4db56f75c084435336ea89d5765edd462b2b..efb7b8615cbed32b893108defb0335ec3e5f8553 100644 (file)
@@ -68,7 +68,7 @@ typedef struct regex {
 #    endif
 #  endif
 ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
-                     bool ignore_case, bool multiline, bool runtime);
+                     bool ignore_case, bool multiline, bool subcaptures, bool runtime);
 int    regex_exec(regex_t *preg, char const *string, size_t len, regmatch_t pmatch[], size_t *nmatch);
 #  ifdef __cplusplus
 }
index 1963a8badfe2c74f3a7cfc06f81d469bfa163e60..4e38a22186a53432c525748e3a0ecbcba799998a 100644 (file)
@@ -1426,7 +1426,7 @@ VALUE_PAIR *pairmake(TALLOC_CTX *ctx, VALUE_PAIR **vps,
 
                talloc_free(vp);
 
-               slen = regex_compile(ctx, &preg, value, strlen(value), false, false, true);
+               slen = regex_compile(ctx, &preg, value, strlen(value), false, false, false, true);
                if (slen <= 0) {
                        fr_strerror_printf("Error at offset %zu compiling regex for %s: %s", -slen,
                                           attribute, fr_strerror());
@@ -1848,7 +1848,7 @@ int paircmp(VALUE_PAIR *a, VALUE_PAIR *b)
 
                        if (!fr_assert(a->da->type == PW_TYPE_STRING)) return -1;
 
-                       slen = regex_compile(NULL, &preg, a->vp_strvalue, a->vp_length, false, false, true);
+                       slen = regex_compile(NULL, &preg, a->vp_strvalue, a->vp_length, false, false, false, true);
                        if (slen <= 0) {
                                fr_strerror_printf("Error at offset %zu compiling regex for %s: %s",
                                                   -slen, a->da->name, fr_strerror());
index aa68836a16ba0ae7fb4ea16dfcb7b398ec3b64f3..ce2b4f9884e340a02d1c169c79ff9df5e83d3a04 100644 (file)
@@ -73,12 +73,14 @@ static void _pcre_free(void *to_free) {
  * @param len of pattern.
  * @param ignore_case whether to do case insensitive matching.
  * @param multiline If true $ matches newlines.
+ * @param subcaptures Whether to compile the regular expression to store subcapture
+ *     data.
  * @param runtime If false run the pattern through the PCRE JIT to convert it to machine code.
  *     This trades startup time (longer) for runtime performance (better).
  * @return >= 1 on success, <= 0 on error. Negative value is offset of parse error.
  */
 ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
-                     bool ignore_case, bool multiline, bool runtime)
+                     bool ignore_case, bool multiline, bool subcaptures, bool runtime)
 {
        char const *error;
        int offset;
@@ -104,6 +106,7 @@ ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_
 
        if (ignore_case) cflags |= PCRE_CASELESS;
        if (multiline) cflags |= PCRE_MULTILINE;
+       if (!subcaptures) cflags |= PCRE_NO_AUTO_CAPTURE;
 
        preg = talloc_zero(ctx, regex_t);
        talloc_set_destructor(preg, _regex_free);
@@ -240,12 +243,14 @@ static int _regex_free(regex_t *preg)
  * @param len of pattern.
  * @param ignore_case Whether the match should be case ignore_case.
  * @param multiline If true $ matches newlines.
+ * @param subcaptures Whether to compile the regular expression to store subcapture
+ *     data.
  * @param runtime Whether the compilation is being done at runtime.
  * @return >= 1 on success, <= 0 on error. Negative value is offset of parse error.
  *     With POSIX regex we only give the correct offset for embedded \0 errors.
  */
 ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
-                     bool ignore_case, bool multiline, UNUSED bool runtime)
+                     bool ignore_case, bool multiline, bool subcaptures, UNUSED bool runtime)
 {
        int ret;
        int cflags = REG_EXTENDED;
@@ -258,6 +263,7 @@ ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_
 
        if (ignore_case) cflags |= REG_ICASE;
        if (multiline) cflags |= REG_NEWLINE;
+       if (!subcaptures) cflags |= REG_NOSUB;
 
 #ifndef HAVE_REGNCOMP
        {
index 0c1ffde6ee2e23af2472744f7ece15cd35edbcd2..321defe99870330a72ce19dc7de152e5eeb699d7 100644 (file)
@@ -180,7 +180,7 @@ static int cond_do_regex(REQUEST *request, fr_cond_t const *c,
                rad_assert(rhs_type == PW_TYPE_STRING);
                rad_assert(rhs->strvalue);
                slen = regex_compile(request, &rreg, rhs->strvalue, rhs_len,
-                                    map->rhs->tmpl_iflag, map->rhs->tmpl_mflag, true);
+                                    map->rhs->tmpl_iflag, map->rhs->tmpl_mflag, true, true);
                if (slen <= 0) {
                        REMARKER(rhs->strvalue, -slen, fr_strerror());
                        EVAL_DEBUG("FAIL %d", __LINE__);
index 62882fcdfa1bd61090511dfbd1e17571efe3ecd3..4445a58f11ceb5d942ff47d29ecc3ad84294adf4 100644 (file)
@@ -3049,7 +3049,7 @@ static bool pass2_regex_compile(CONF_ITEM const *ci, value_pair_tmpl_t *vpt)
        }
 
        slen = regex_compile(vpt, &preg, vpt->name, vpt->len,
-                            vpt->tmpl_iflag, vpt->tmpl_mflag, false);
+                            vpt->tmpl_iflag, vpt->tmpl_mflag, true, false);
        if (slen <= 0) {
                char *spaces, *text;
 
index 9cbd920bd858b48aa38e75cb7cf4c3bb737ed545..80acf57aab4484853f292d600034f834f4b34150 100644 (file)
@@ -103,7 +103,7 @@ int radius_compare_vps(UNUSED REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *v
                /*
                 *      Include substring matches.
                 */
-               slen = regex_compile(request, &preg, expr_p, talloc_array_length(expr_p) - 1, false, false, true);
+               slen = regex_compile(request, &preg, expr_p, talloc_array_length(expr_p) - 1, false, false, true, true);
                if (slen <= 0) {
                        REMARKER(expr_p, -slen, fr_strerror());
 
index ad65366fe73d8e134c07476c724d939eb6caf698..36126eb941efe28c52e01da0027c25f97dcf7aea 100644 (file)
@@ -1921,7 +1921,7 @@ int realm_realm_add(REALM *r, UNUSED CONF_SECTION *cs)
                /*
                 *      Include substring matches.
                 */
-               slen = regex_compile(rr, &rr->preg, r->name + 1, strlen(r->name) - 1, true, false, false);
+               slen = regex_compile(rr, &rr->preg, r->name + 1, strlen(r->name) - 1, true, false, false, false);
                if (slen <= 0) {
                        char *spaces, *text;