diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2011-11-26 12:16:27 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2011-11-26 12:16:27 -0500 |
commit | e75d41f0c3e69fefe24a98514b897716d60a83dd (patch) | |
tree | 60385c07bb7300fbcbeeacaeae545d0fc2105409 /src/pl/plperl/plperl_helpers.h | |
parent | 6b5510e8d64f9c76b1c24c46537d5a83a3483778 (diff) | |
download | postgresql-e75d41f0c3e69fefe24a98514b897716d60a83dd.tar.gz postgresql-e75d41f0c3e69fefe24a98514b897716d60a83dd.zip |
Ensure plperl strings are always correctly UTF8 encoded.
Amit Khandekar and Alex Hunsaker.
Backpatched to 9.1 where the problem first occurred.
Diffstat (limited to 'src/pl/plperl/plperl_helpers.h')
-rw-r--r-- | src/pl/plperl/plperl_helpers.h | 13 |
1 files changed, 12 insertions, 1 deletions
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; } |