summaryrefslogtreecommitdiff
path: root/src/include/regex
diff options
context:
space:
mode:
authorTom Lane2015-10-02 18:51:58 +0000
committerTom Lane2015-10-02 18:51:58 +0000
commitb63fc28776c5d2efdb4de326ad0f0b5b88f82220 (patch)
tree74bf395229d6c60aa24463714340ce1e41fdfc14 /src/include/regex
parentf2c4ffc3307cab6619a28e77da9211416c8b1d83 (diff)
Add recursion depth protections to regular expression matching.
Some of the functions in regex compilation and execution recurse, and therefore could in principle be driven to stack overflow. The Tcl crew has seen this happen in practice in duptraverse(), though their fix was to put in a hard-wired limit on the number of recursive levels, which is not too appetizing --- fortunately, we have enough infrastructure to check the actually available stack. Greg Stark has also seen it in other places while fuzz testing on a machine with limited stack space. Let's put guards in to prevent crashes in all these places. Since the regex code would leak memory if we simply threw elog(ERROR), we have to introduce an API that checks for stack depth without throwing such an error. Fortunately that's not difficult.
Diffstat (limited to 'src/include/regex')
-rw-r--r--src/include/regex/regguts.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h
index fccaf298bf1..32777523551 100644
--- a/src/include/regex/regguts.h
+++ b/src/include/regex/regguts.h
@@ -449,11 +449,15 @@ struct fns
{
void FUNCPTR(free, (regex_t *));
int FUNCPTR(cancel_requested, (void));
+ int FUNCPTR(stack_too_deep, (void));
};
#define CANCEL_REQUESTED(re) \
((*((struct fns *) (re)->re_fns)->cancel_requested) ())
+#define STACK_TOO_DEEP(re) \
+ ((*((struct fns *) (re)->re_fns)->stack_too_deep) ())
+
/*
* the insides of a regex_t, hidden behind a void *