aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-02-02 03:07:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-02-02 03:07:08 +0000
commit9fe097577e0f3fac916c5df8024e3cc27e1f35cd (patch)
tree6986c5f1fdbe935ca515c3173816fe836223f72a
parentb8362d465ddf58681d26333faa93334716d87493 (diff)
downloadpostgresql-9fe097577e0f3fac916c5df8024e3cc27e1f35cd.tar.gz
postgresql-9fe097577e0f3fac916c5df8024e3cc27e1f35cd.zip
Avoid generating invalid character encoding sequences in make_greater_string.
Not sure how this mistake evaded detection for so long.
-rw-r--r--src/backend/utils/adt/selfuncs.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index a11e85a56d5..84f18dc9359 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.155 2004/01/17 20:09:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.156 2004/02/02 03:07:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -3742,6 +3742,11 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
*
* 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.
+ *
+ * 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 *
make_greater_string(const Const *str_const)
@@ -3788,13 +3793,20 @@ make_greater_string(const Const *str_const)
/*
* Try to generate a larger string by incrementing the last byte.
*/
- if (*lastchar < (unsigned char) 255)
+ while (*lastchar < (unsigned char) 255)
{
Const *workstr_const;
(*lastchar)++;
+
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);
+ }
else
workstr_const = string_to_bytea_const(workstr, len);