(parameters and operators) in a single expression is limited to 256.
Regular expression patterns used with the `=~` and `!~` operators are limited to
-256 bytes. Patterns with consecutive quantifiers (e.g., `a++`, `a**`) or nested
-group repetitions (e.g., `(a+)+`) are rejected because they can cause excessive
+256 bytes. Patterns with consecutive quantifiers (e.g., `a++`, `a**`), nested
+group repetitions (e.g., `(a+)+`), or interval repetitions with bounds larger
+than 1024 (e.g., `{,9999}`) are rejected because they can cause excessive
memory consumption in the POSIX regex compiler.
== AUTHORS
return (struct filter_node *) n;
}
-/* Consecutive ERE quantifiers (a++, a**) and nested group repetitions
- * ((a+)+, (a*)*) cause glibc regcomp() to allocate gigabytes for the NFA. */
+/* Consecutive ERE quantifiers (a++, a**), nested group repetitions
+ * ((a+)+, (a*)*), and large interval bounds ({,N} where N is huge)
+ * cause glibc regcomp() to allocate gigabytes for the NFA. */
static int is_unsafe_regex(const char *pattern)
{
size_t i, len = strlen(pattern);
return 1;
}
}
+
+ /* reject large ERE interval bounds like {,32232} or {1,9999} */
+ if (pattern[i] == '{') {
+ const char *p = &pattern[i + 1];
+
+ while (*p && *p != '}') {
+ if (*p >= '0' && *p <= '9') {
+ unsigned long val;
+ char *end = NULL;
+
+ errno = 0;
+ val = strtoul(p, &end, 10);
+ if (errno || val > SCOLS_FILTER_MAX_REPCNT)
+ return 1;
+ p = end;
+ } else
+ p++;
+ }
+ }
}
return 0;
}
#define SCOLS_FILTER_MAX_EXPRSZ 1024
#define SCOLS_FILTER_MAX_NODES 256
#define SCOLS_FILTER_MAX_REGSZ 256
+#define SCOLS_FILTER_MAX_REPCNT 1024
struct filter_node *__filter_new_node(enum filter_ntype type, size_t sz);
void filter_ref_node(struct filter_node *n);