1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-24 09:27:52 +03:00

Avoid generating invalid character encoding sequences in make_greater_string.

Not sure how this mistake evaded detection for so long.
This commit is contained in:
Tom Lane
2004-02-02 03:07:14 +00:00
parent a2b5cc81df
commit a8fcb748e3

View File

@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.147.2.1 2003/12/07 04:12:50 joe Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.147.2.2 2004/02/02 03:07:14 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -3738,6 +3738,11 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
* *
* This could be rather slow in the worst case, but in most cases we * This could be rather slow in the worst case, but in most cases we
* won't have to try more than one or two strings before succeeding. * won't have to try more than one or two strings before succeeding.
*
* NOTE: at present this assumes we are in the C locale, so that simple
* bytewise comparison applies. However, we might be in a multibyte
* encoding such as UTF-8, so we do have to watch out for generating
* invalid encoding sequences.
*/ */
Const * Const *
make_greater_string(const Const *str_const) make_greater_string(const Const *str_const)
@@ -3784,13 +3789,20 @@ make_greater_string(const Const *str_const)
/* /*
* Try to generate a larger string by incrementing the last byte. * Try to generate a larger string by incrementing the last byte.
*/ */
if (*lastchar < (unsigned char) 255) while (*lastchar < (unsigned char) 255)
{ {
Const *workstr_const; Const *workstr_const;
(*lastchar)++; (*lastchar)++;
if (datatype != BYTEAOID) if (datatype != BYTEAOID)
{
/* do not generate invalid encoding sequences */
if (!pg_verifymbstr((const unsigned char *) workstr,
len, true))
continue;
workstr_const = string_to_const(workstr, datatype); workstr_const = string_to_const(workstr, datatype);
}
else else
workstr_const = string_to_bytea_const(workstr, len); workstr_const = string_to_bytea_const(workstr, len);