]> granicus.if.org Git - postgresql/commitdiff
Fix text_position to not scan past end of source string in multibyte
authorJoe Conway <mail@joeconway.com>
Sun, 1 Feb 2004 04:05:13 +0000 (04:05 +0000)
committerJoe Conway <mail@joeconway.com>
Sun, 1 Feb 2004 04:05:13 +0000 (04:05 +0000)
case, per report from Korea PostgreSQL Users' Group. Copied from Tom
Lane's 7.4 branch patch.

src/backend/utils/adt/varlena.c

index 9c3faaf2a4c889d03e252a337565a8061a46b99f..d4276ac1015966f0fca03d6a6fe521df5af64c31 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92.2.2 2003/11/30 20:52:37 joe Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.92.2.3 2004/02/01 04:05:13 joe Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -665,9 +665,6 @@ text_position(Datum str, Datum search_str, int matchnum)
        len1 = (VARSIZE(t1) - VARHDRSZ);
        len2 = (VARSIZE(t2) - VARHDRSZ);
 
-       /* no use in searching str past point where search_str will fit */
-       px = (len1 - len2);
-
        if (eml == 1)                           /* simple case - single byte encoding */
        {
                char       *p1,
@@ -676,6 +673,9 @@ text_position(Datum str, Datum search_str, int matchnum)
                p1 = VARDATA(t1);
                p2 = VARDATA(t2);
 
+               /* no use in searching str past point where search_str will fit */
+               px = (len1 - len2);
+
                for (p = 0; p <= px; p++)
                {
                        if ((*p2 == *p1) && (strncmp(p1, p2, len2) == 0))
@@ -703,6 +703,9 @@ text_position(Datum str, Datum search_str, int matchnum)
                (void) pg_mb2wchar_with_len((unsigned char *) VARDATA(t2), p2, len2);
                len2 = pg_wchar_strlen(p2);
 
+               /* no use in searching str past point where search_str will fit */
+               px = (len1 - len2);
+
                for (p = 0; p <= px; p++)
                {
                        if ((*p2 == *p1) && (pg_wchar_strncmp(p1, p2, len2) == 0))