summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-11-10 14:57:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-11-10 14:57:53 +0000
commit8f74153732c512baa498eb6c38244c0d3a09dff8 (patch)
tree598d66ab6b1ef6f97ce2bdc687460ae0316ec35d
parent400e915c6227cc91967b286d466a2c18d2bfce2e (diff)
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.
-rw-r--r--contrib/sslinfo/sslinfo.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c
index 16eea5eae33..f1fd9983917 100644
--- a/contrib/sslinfo/sslinfo.c
+++ b/contrib/sslinfo/sslinfo.c
@@ -4,7 +4,7 @@
* Written by Victor B. Wagner <vitus@cryptocom.ru>, Cryptocom LTD
* This file is distributed under BSD-style license.
*
- * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.5 2006/10/04 00:29:46 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.5.2.1 2008/11/10 14:57:53 tgl Exp $
*/
#include "postgres.h"
@@ -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);
}