From: Tom Lane Date: Mon, 10 Nov 2008 14:57:53 +0000 (+0000) Subject: Fix old bug in contrib/sslinfo: X509_NAME_to_text freed the BIO_s_mem buffer X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=cbd32a87181de57bb495fe1afcec2c71a5669111;p=users%2Fbernd%2Fpostgres.git Fix old bug in contrib/sslinfo: X509_NAME_to_text freed the BIO_s_mem buffer it was using too soon. In a situation where pg_do_encoding_conversion is a no-op, this led to garbage data returned. In HEAD, also modify the code that's ensuring null termination to make it a tad more obvious what's happening. --- diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c index 4bd8f2838b..d2d6160170 100644 --- a/contrib/sslinfo/sslinfo.c +++ b/contrib/sslinfo/sslinfo.c @@ -306,22 +306,17 @@ X509_NAME_to_text(X509_NAME *name) i = 0; BIO_write(membuf, &i, 1); size = BIO_get_mem_data(membuf, &sp); - dp = (char *) pg_do_encoding_conversion((unsigned char *) sp, size - 1, PG_UTF8, GetDatabaseEncoding()); - BIO_free(membuf); outlen = strlen(dp); result = palloc(VARHDRSZ + outlen); memcpy(VARDATA(result), dp, outlen); - - /* - * pg_do_encoding_conversion has annoying habit of returning source - * pointer - */ if (dp != sp) pfree(dp); + + BIO_free(membuf); VARATT_SIZEP(result) = outlen + VARHDRSZ; PG_RETURN_TEXT_P(result); }