]> granicus.if.org Git - postgresql/commitdiff
Add recursion depth protection to LIKE matching.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Oct 2015 19:00:52 +0000 (15:00 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 2 Oct 2015 19:00:52 +0000 (15:00 -0400)
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
src/backend/utils/adt/like_match.c

index 3137711c38458f65dc917377961d8c41d45aec5f..2575c2550110197ba26710532e32d49aa9bf0d45 100644 (file)
@@ -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"
 
index 214664116d7f8109051470f326b1830e6e136adb..0a650e957d82bb535757f80416202b326a854a9b 100644 (file)
@@ -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