diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2011-11-26 12:19:38 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2011-11-26 12:19:38 -0500 |
commit | 4cdb41b54e432ee75e3c61e990b735b15fa66e81 (patch) | |
tree | f87b77ae86664d2e925e4d9765375d675c2cd447 /src/pl/plperl/plperl_helpers.h | |
parent | fd6dbc24ef1dc6b39a795b5e0e959cf500ad71d6 (diff) | |
download | postgresql-4cdb41b54e432ee75e3c61e990b735b15fa66e81.tar.gz postgresql-4cdb41b54e432ee75e3c61e990b735b15fa66e81.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; } |