This is an automated email from the git hooks/post-receive script. myon pushed a commit to branch master in repository libdbd-pg-perl.
commit f29a19e77104507ea3a8f289de3725d0cffbe63e Author: David Christensen <da...@endpoint.com> Date: Wed Sep 13 11:49:03 2017 -0500 Protect against crash if missing client_encoding If "client_encoding" was not exposed as a connection parameter via libpq (as might be in a custom wire-protocol-based application) the pg_db_detect_client_encoding_utf8() function would crash. Test for NULL to prevent this and set the appropriate default value. Reported-by: Marko Tiikkaja <ma...@joh.to> --- Changes | 3 +++ dbdimp.c | 29 +++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index ab0ea60..1563d6a 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,9 @@ - Fix running tests with non-UTF8 server_encoding (Github issue #26) + - Fix crash with missing client_encoding + (Github issue #29) + [David Christensen, reported by Marko Tiikkaja] Version 3.6.2 Released May 23, 2017 (git tag 3.6.2) diff --git a/dbdimp.c b/dbdimp.c index 7976189..065360c 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -2992,18 +2992,23 @@ static void pg_db_detect_client_encoding_utf8(pTHX_ imp_dbh_t *imp_dbh) { int i, j; const char * const client_encoding = PQparameterStatus(imp_dbh->conn, "client_encoding"); - STRLEN len = strlen(client_encoding); - Newx(clean_encoding, len + 1, char); - for (i = 0, j = 0; i < len; i++) { - const char c = toLOWER(client_encoding[i]); - if (isALPHA(c) || isDIGIT(c)) - clean_encoding[j++] = c; - }; - clean_encoding[j] = '\0'; - imp_dbh->client_encoding_utf8 = - (strnEQ(clean_encoding, "utf8", 4) || strnEQ(clean_encoding, "unicode", 8)) - ? DBDPG_TRUE : DBDPG_FALSE; - Safefree(clean_encoding); + if (NULL != client_encoding) { + STRLEN len = strlen(client_encoding); + Newx(clean_encoding, len + 1, char); + for (i = 0, j = 0; i < len; i++) { + const char c = toLOWER(client_encoding[i]); + if (isALPHA(c) || isDIGIT(c)) + clean_encoding[j++] = c; + }; + clean_encoding[j] = '\0'; + imp_dbh->client_encoding_utf8 = + (strnEQ(clean_encoding, "utf8", 4) || strnEQ(clean_encoding, "unicode", 8)) + ? DBDPG_TRUE : DBDPG_FALSE; + Safefree(clean_encoding); + } + else { + imp_dbh->client_encoding_utf8 = DBDPG_FALSE; + } } /* ================================================================== */ -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdbd-pg-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits