Skip to content

Commit 9fe0975

Browse files
committed
Avoid generating invalid character encoding sequences in make_greater_string.
Not sure how this mistake evaded detection for so long.
1 parent b8362d4 commit 9fe0975

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.155 2004/01/17 20:09:35 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.156 2004/02/02 03:07:08 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -3742,6 +3742,11 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
37423742
*
37433743
* This could be rather slow in the worst case, but in most cases we
37443744
* won't have to try more than one or two strings before succeeding.
3745+
*
3746+
* NOTE: at present this assumes we are in the C locale, so that simple
3747+
* bytewise comparison applies. However, we might be in a multibyte
3748+
* encoding such as UTF-8, so we do have to watch out for generating
3749+
* invalid encoding sequences.
37453750
*/
37463751
Const *
37473752
make_greater_string(const Const *str_const)
@@ -3788,13 +3793,20 @@ make_greater_string(const Const *str_const)
37883793
/*
37893794
* Try to generate a larger string by incrementing the last byte.
37903795
*/
3791-
if (*lastchar < (unsigned char) 255)
3796+
while (*lastchar < (unsigned char) 255)
37923797
{
37933798
Const *workstr_const;
37943799

37953800
(*lastchar)++;
3801+
37963802
if (datatype != BYTEAOID)
3803+
{
3804+
/* do not generate invalid encoding sequences */
3805+
if (!pg_verifymbstr((const unsigned char *) workstr,
3806+
len, true))
3807+
continue;
37973808
workstr_const = string_to_const(workstr, datatype);
3809+
}
37983810
else
37993811
workstr_const = string_to_bytea_const(workstr, len);
38003812

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy