mirror of
https://github.com/postgres/postgres.git
synced 2025-05-17 06:41:24 +03:00
Make replace(), split_part(), and string_to_array() behave somewhat sanely
when handed an invalidly-encoded pattern. The previous coding could get into an infinite loop if pg_mb2wchar_with_len() returned a zero-length string after we'd tested for nonempty pattern; which is exactly what it will do if the string consists only of an incomplete multibyte character. This led to either an out-of-memory error or a backend crash depending on platform. Per report from Wiktor Wodecki.
This commit is contained in:
parent
da15b2852e
commit
6e606074e1
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.106.2.7 2006/10/07 00:12:12 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.106.2.8 2007/07/19 20:34:48 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -799,6 +799,8 @@ text_position(Datum str, Datum search_str, int matchnum)
|
|||||||
(void) pg_mb2wchar_with_len((unsigned char *) VARDATA(t2), p2, len2);
|
(void) pg_mb2wchar_with_len((unsigned char *) VARDATA(t2), p2, len2);
|
||||||
len2 = pg_wchar_strlen(p2);
|
len2 = pg_wchar_strlen(p2);
|
||||||
|
|
||||||
|
if (len1 > 0 && len2 > 0)
|
||||||
|
{
|
||||||
/* no use in searching str past point where search_str will fit */
|
/* no use in searching str past point where search_str will fit */
|
||||||
px = (len1 - len2);
|
px = (len1 - len2);
|
||||||
|
|
||||||
@ -816,6 +818,7 @@ text_position(Datum str, Datum search_str, int matchnum)
|
|||||||
}
|
}
|
||||||
p1++;
|
p1++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pfree(ps1);
|
pfree(ps1);
|
||||||
pfree(ps2);
|
pfree(ps2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user