From 7103e743f9df95d8fdf9fd94a878173c3a988d3d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 30 Jan 2008 04:11:19 +0000 Subject: [PATCH] Don't putenv() a string that is allocated in a context that will go away soon. I suspect this explains bug #3902, though I'm still not able to reproduce that. --- src/backend/libpq/auth.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index d873e71782..3c52e6d008 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -384,7 +384,6 @@ pg_GSS_recvauth(Port *port) min_stat, lmin_s, gflags; - char *kt_path; int mtype; int ret; StringInfoData buf; @@ -398,11 +397,19 @@ pg_GSS_recvauth(Port *port) * setenv("KRB5_KTNAME", pg_krb_server_keyfile, 0); except setenv() * not always available. */ - if (!getenv("KRB5_KTNAME")) + if (getenv("KRB5_KTNAME") == NULL) { - kt_path = palloc(MAXPGPATH + 13); - snprintf(kt_path, MAXPGPATH + 13, - "KRB5_KTNAME=%s", pg_krb_server_keyfile); + size_t kt_len = strlen(pg_krb_server_keyfile) + 14; + char *kt_path = malloc(kt_len); + + if (!kt_path) + { + ereport(LOG, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); + return STATUS_ERROR; + } + snprintf(kt_path, kt_len, "KRB5_KTNAME=%s", pg_krb_server_keyfile); putenv(kt_path); } } -- 2.39.5