From a8fb55c5095f0a42896c775efaf8e4a867cd71bc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 10 Nov 2008 14:57:46 +0000 Subject: [PATCH] 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. --- contrib/sslinfo/sslinfo.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c index e103b02305..62c3e3c6da 100644 --- a/contrib/sslinfo/sslinfo.c +++ b/contrib/sslinfo/sslinfo.c @@ -312,19 +312,14 @@ X509_NAME_to_text(X509_NAME *name) size - 1, PG_UTF8, GetDatabaseEncoding()); - BIO_free(membuf); - outlen = strlen(dp); result = palloc(VARHDRSZ + outlen); memcpy(VARDATA(result), dp, outlen); SET_VARSIZE(result, VARHDRSZ + outlen); - /* - * pg_do_encoding_conversion has annoying habit of returning source - * pointer - */ if (dp != sp) pfree(dp); + BIO_free(membuf); PG_RETURN_TEXT_P(result); } -- 2.39.5