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.
This commit is contained in:
Tom Lane 2008-01-30 04:11:19 +00:00
parent 65b39ec347
commit b58d8c9a53

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.162 2008/01/01 19:45:49 momjian Exp $
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.163 2008/01/30 04:11:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -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);
}
}