From e75d41f0c3e69fefe24a98514b897716d60a83dd Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sat, 26 Nov 2011 12:16:27 -0500 Subject: Ensure plperl strings are always correctly UTF8 encoded. Amit Khandekar and Alex Hunsaker. Backpatched to 9.1 where the problem first occurred. --- src/pl/plperl/plperl_helpers.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/pl/plperl/plperl_helpers.h') diff --git a/src/pl/plperl/plperl_helpers.h b/src/pl/plperl/plperl_helpers.h index 81c177b164b..ac0a97d7aa6 100644 --- a/src/pl/plperl/plperl_helpers.h +++ b/src/pl/plperl/plperl_helpers.h @@ -7,10 +7,21 @@ static inline char * utf_u2e(const char *utf8_str, size_t len) { - char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, GetDatabaseEncoding()); + int enc = GetDatabaseEncoding(); + + char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, enc); + + /* + * when we are a PG_UTF8 or SQL_ASCII database + * pg_do_encoding_conversion() will not do any conversion or + * verification. we need to do it manually instead. + */ + if (enc == PG_UTF8 || enc == PG_SQL_ASCII) + pg_verify_mbstr_len(PG_UTF8, utf8_str, len, false); if (ret == utf8_str) ret = pstrdup(ret); + return ret; } -- cgit v1.2.3