Skip to content

Commit b875ca0

Browse files
committed
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.
1 parent 54b116d commit b875ca0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/backend/utils/adt/like.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ctype.h>
2121

2222
#include "mb/pg_wchar.h"
23+
#include "miscadmin.h"
2324
#include "utils/builtins.h"
2425

2526

src/backend/utils/adt/like_match.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ MatchText(char *t, int tlen, char *p, int plen)
8282
if (plen == 1 && *p == '%')
8383
return LIKE_TRUE;
8484

85+
/* Since this function recurses, it could be driven to stack overflow */
86+
check_stack_depth();
87+
8588
/*
8689
* In this loop, we advance by char when matching wildcards (and thus on
8790
* recursive entry to this function we are properly char-synced). On other

0 commit comments

Comments
 (0)