Skip to content

Commit bdc5d95

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 20c6277 commit bdc5d95

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/backend/utils/adt/like.c

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "catalog/pg_collation.h"
2323
#include "mb/pg_wchar.h"
24+
#include "miscadmin.h"
2425
#include "utils/builtins.h"
2526
#include "utils/pg_locale.h"
2627

src/backend/utils/adt/like_match.c

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ MatchText(char *t, int tlen, char *p, int plen,
8383
if (plen == 1 && *p == '%')
8484
return LIKE_TRUE;
8585

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

0 commit comments

Comments
 (0)