summaryrefslogtreecommitdiff
path: root/src/backend/regex
diff options
context:
space:
mode:
authorJeff Davis2023-04-21 15:19:41 +0000
committerJeff Davis2023-04-21 15:19:41 +0000
commitc04c6c5d6f5f213f217f1e356bf1c2d8b4e255a2 (patch)
tree2a045c0ab3da75d11215d4a5d8b34bf81f1ffe66 /src/backend/regex
parenta23ab2eebfb19bacb9e8d91edb822a0fec37334c (diff)
Avoid character classification in regex escape parsing.
For regex escape sequences, just test directly for the relevant ASCII characters rather than using locale-sensitive character classification. This fixes an assertion failure when a locale considers a non-ASCII character, such as "൧", to be a digit. Reported-by: Richard Guo Discussion: https://postgr.es/m/CAMbWs49Q6UoKGeT8pBkMtJGJd+16CBFZaaWUk9Du+2ERE5g_YA@mail.gmail.com Backpatch-through: 11
Diffstat (limited to 'src/backend/regex')
-rw-r--r--src/backend/regex/regc_lex.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/regex/regc_lex.c b/src/backend/regex/regc_lex.c
index 4780d79f097..38c09b11232 100644
--- a/src/backend/regex/regc_lex.c
+++ b/src/backend/regex/regc_lex.c
@@ -613,7 +613,11 @@ lexescape(struct vars *v)
assert(!ATEOS());
c = *v->now++;
- if (!iscalnum(c))
+
+ /* if it's not alphanumeric ASCII, treat it as a plain character */
+ if (!('a' <= c && c <= 'z') &&
+ !('A' <= c && c <= 'Z') &&
+ !('0' <= c && c <= '9'))
RETV(PLAIN, c);
NOTE(REG_UNONPOSIX);
@@ -755,8 +759,11 @@ lexescape(struct vars *v)
RETV(PLAIN, c);
break;
default:
- assert(iscalpha(c));
- FAILW(REG_EESCAPE); /* unknown alphabetic escape */
+ /*
+ * Throw an error for unrecognized ASCII alpha escape sequences,
+ * which reserves them for future use if needed.
+ */
+ FAILW(REG_EESCAPE);
break;
}
assert(NOTREACHED);