aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@esdenera.com>2015-06-23 13:15:49 +0200
committerReyk Floeter <reyk@esdenera.com>2015-06-23 13:15:49 +0200
commitd0ff6c5d27b28a2a77e9411a929f500c79e647f8 (patch)
tree06cad3a063b128c6fc7d2377750863e30b383f6e
parent27068d85acf018899883abbeb23abcefe48ded1f (diff)
parent3873b23c53de31074d294d127077e691662150c2 (diff)
downloadhttpd-d0ff6c5d27b28a2a77e9411a929f500c79e647f8.tar.gz
httpd-d0ff6c5d27b28a2a77e9411a929f500c79e647f8.zip
Merge branch 'experiment-2' into patterns
-rw-r--r--httpd/patterns.c13
-rw-r--r--httpd/patterns.h3
-rw-r--r--regress/patterns/test-patterns-lua.out28
-rw-r--r--regress/patterns/test-patterns.in4
-rw-r--r--regress/patterns/test-patterns.out12
5 files changed, 53 insertions, 7 deletions
diff --git a/httpd/patterns.c b/httpd/patterns.c
index e6e1b1f..08c1e27 100644
--- a/httpd/patterns.c
+++ b/httpd/patterns.c
@@ -48,6 +48,7 @@
struct match_state {
int matchdepth; /* control for recursive depth (to avoid C
* stack overflow) */
+ int repetitioncounter; /* control the repetition items */
int maxcaptures; /* configured capture limit */
const char *src_init; /* init of source string */
const char *src_end; /* end ('\0') of source string */
@@ -425,13 +426,12 @@ match(struct match_state *ms, const char *s, const char *p)
/* does not match at least once? */
if (!singlematch(ms, s, p, ep)) {
- if (ms->matchdepth-- == 0) {
- match_error(ms, "pattern too complex");
- s = NULL; /* failed */
- }
-
+ if (ms->repetitioncounter-- == 0) {
+ match_error(ms, "max repetition items");
+ s = NULL; /* fail */
/* accept empty? */
- if (*ep == '*' || *ep == '?' || *ep == '-') {
+ } else if
+ (*ep == '*' || *ep == '?' || *ep == '-') {
p = ep + 1;
/* return match(ms, s, ep + 1); */
goto init;
@@ -620,6 +620,7 @@ str_find_aux(struct match_state *ms, const char *pattern, const char *string,
}
ms->maxcaptures = (nsm > MAXCAPTURES ? MAXCAPTURES : nsm) - 1;
ms->matchdepth = MAXCCALLS;
+ ms->repetitioncounter = MAXREPETITION;
ms->src_init = s;
ms->src_end = s + ls;
ms->p_end = p + lp;
diff --git a/httpd/patterns.h b/httpd/patterns.h
index 28b0f95..6db5991 100644
--- a/httpd/patterns.h
+++ b/httpd/patterns.h
@@ -23,7 +23,8 @@
#define PATTERNS_H
#define MAXCAPTURES 32 /* Max no. of allowed captures in pattern */
-#define MAXCCALLS 5000 /* Max recusion depth in pattern matching */
+#define MAXCCALLS 200 /* Max recusion depth in pattern matching */
+#define MAXREPETITION 0xfffff /* Max for repetition items */
struct str_find {
off_t sm_so; /* start offset of match */
diff --git a/regress/patterns/test-patterns-lua.out b/regress/patterns/test-patterns-lua.out
index cd9fe6a..0cab468 100644
--- a/regress/patterns/test-patterns-lua.out
+++ b/regress/patterns/test-patterns-lua.out
@@ -98,3 +98,31 @@ stack traceback:
[C]: in function 'string.match'
./patterns-tester.lua:2: in main chunk
[C]: in ?
+string='q*********************************'
+pattern='*************************************q'
+lua53: ./patterns-tester.lua:2: max repetition items
+stack traceback:
+ [C]: in function 'string.match'
+ ./patterns-tester.lua:2: in main chunk
+ [C]: in ?
+string='q+++++++++++++++++++++++++++++++++'
+pattern='+++++++++++++++++++++++++++++++++++++q'
+lua53: ./patterns-tester.lua:2: max repetition items
+stack traceback:
+ [C]: in function 'string.match'
+ ./patterns-tester.lua:2: in main chunk
+ [C]: in ?
+string='q---------------------------------'
+pattern='-------------------------------------q'
+lua53: ./patterns-tester.lua:2: max repetition items
+stack traceback:
+ [C]: in function 'string.match'
+ ./patterns-tester.lua:2: in main chunk
+ [C]: in ?
+string='q?????????????????????????????????'
+pattern='?????????????????????????????????????q'
+lua53: ./patterns-tester.lua:2: max repetition items
+stack traceback:
+ [C]: in function 'string.match'
+ ./patterns-tester.lua:2: in main chunk
+ [C]: in ?
diff --git a/regress/patterns/test-patterns.in b/regress/patterns/test-patterns.in
index 46aa506..5abef1f 100644
--- a/regress/patterns/test-patterns.in
+++ b/regress/patterns/test-patterns.in
@@ -21,3 +21,7 @@ xxxx ^x*$ same as before
/page/51 ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() too many captures
/page/51 /page/%f missing '[' after '%f' in pattern
/page/51 /page%f/51 missing '[' after '%f' in pattern
+q********************************* *************************************q max repetition items
+q+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++q max repetition items
+q--------------------------------- -------------------------------------q max repetition items
+q????????????????????????????????? ?????????????????????????????????????q max repetition items
diff --git a/regress/patterns/test-patterns.out b/regress/patterns/test-patterns.out
index 1999cc1..aecb9f0 100644
--- a/regress/patterns/test-patterns.out
+++ b/regress/patterns/test-patterns.out
@@ -85,3 +85,15 @@ pattern='/page/%f'
patterns-tester: str_match: missing '[' after '%f' in pattern
string='/page/51'
pattern='/page%f/51'
+patterns-tester: str_match: max repetition items
+string='q*********************************'
+pattern='*************************************q'
+patterns-tester: str_match: max repetition items
+string='q+++++++++++++++++++++++++++++++++'
+pattern='+++++++++++++++++++++++++++++++++++++q'
+patterns-tester: str_match: max repetition items
+string='q---------------------------------'
+pattern='-------------------------------------q'
+patterns-tester: str_match: max repetition items
+string='q?????????????????????????????????'
+pattern='?????????????????????????????????????q'