postgres.git / summary / log / commit / refs
commit 57bf7b54831b68f63cea006b988e82cccb3469de
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri Oct 02 19:00:52 2015 +0000
First released in: 9.6.0, 9.0.23, 9.1.19, 9.2.14, 9.3.10, 9.4.5, 9.5.0
Add recursion depth protection to LIKE matching.
Since MatchText() recurses, it could in principle be driven to stack
overflow, although quite a long pattern would be needed.
src/backend/utils/adt/like.c | 1 +
src/backend/utils/adt/like_match.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 6e2aa9a86dc..845931d998d 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -21,6 +21,7 @@
#include "catalog/pg_collation.h"
#include "mb/pg_wchar.h"
+#include "miscadmin.h"
#include "utils/builtins.h"
#include "utils/pg_locale.h"
diff --git a/src/backend/utils/adt/like_match.c b/src/backend/utils/adt/like_match.c
index fcd36f09ee1..89814a4b56c 100644
--- a/src/backend/utils/adt/like_match.c
+++ b/src/backend/utils/adt/like_match.c
@@ -83,6 +83,9 @@ MatchText(char *t, int tlen, char *p, int plen,
if (plen == 1 && *p == '%')
return LIKE_TRUE;
+ /* Since this function recurses, it could be driven to stack overflow */
+ check_stack_depth();
+
/*
* In this loop, we advance by char when matching wildcards (and thus on
* recursive entry to this function we are properly char-synced). On other
[parent: a0c089f33f29]