Hi,

SplitIdentifierString can run pretty much forever without hitting a CFI.  This
is mostly due to scan_quoted_identifier having O(n2) complexity, but the same
problem exists to a lesser degree in SplitIdentifierString.

I hit that problem by setting by mistake (bug in a some client app) search_path
to a big list of double quotes.

Simple patch attached, adding a couple of CFI in the mentioned functions.
>From f6825747aafe2973fd710215647e5628c1e715be Mon Sep 17 00:00:00 2001
From: Julien Rouhaud <[email protected]>
Date: Wed, 2 Dec 2026 14:31:00 +0800
Subject: [PATCH] Add CHECK_FOR_INTERRUPTS in SplitIdentifierString

This commit adds CHECK_FOR_INTERRUPTS to loops in SplitIdentifierString and
underlying scan_quoted_identifier functions.  Both can process quite large
amount of data and the latter has quadratic complexity.
---
 src/backend/utils/adt/varlena.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 2b03a2b621c..8ab612182e7 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -2771,6 +2771,8 @@ scan_quoted_identifier(char **endp, char **nextp)
 
        for (;;)
        {
+               CHECK_FOR_INTERRUPTS();
+
                *endp = strchr(*nextp + 1, '"');
                if (*endp == NULL)
                        return NULL;            /* mismatched quotes */
@@ -2885,6 +2887,8 @@ SplitIdentifierString(char *rawstring, char separator,
                char       *curname;
                char       *endp;
 
+               CHECK_FOR_INTERRUPTS();
+
                curname = scan_identifier(&endp, &nextp, separator, true);
                if (curname == NULL)
                        return false;           /* mismatched quotes or empty 
name */
-- 
2.56.1

Reply via email to