Skip to content

Commit b58d8c9

Browse files
committed
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.
1 parent 65b39ec commit b58d8c9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/backend/libpq/auth.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.162 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/auth.c,v 1.163 2008/01/30 04:11:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -384,7 +384,6 @@ pg_GSS_recvauth(Port *port)
384384
min_stat,
385385
lmin_s,
386386
gflags;
387-
char *kt_path;
388387
int mtype;
389388
int ret;
390389
StringInfoData buf;
@@ -398,11 +397,19 @@ pg_GSS_recvauth(Port *port)
398397
* setenv("KRB5_KTNAME", pg_krb_server_keyfile, 0); except setenv()
399398
* not always available.
400399
*/
401-
if (!getenv("KRB5_KTNAME"))
400+
if (getenv("KRB5_KTNAME") == NULL)
402401
{
403-
kt_path = palloc(MAXPGPATH + 13);
404-
snprintf(kt_path, MAXPGPATH + 13,
405-
"KRB5_KTNAME=%s", pg_krb_server_keyfile);
402+
size_t kt_len = strlen(pg_krb_server_keyfile) + 14;
403+
char *kt_path = malloc(kt_len);
404+
405+
if (!kt_path)
406+
{
407+
ereport(LOG,
408+
(errcode(ERRCODE_OUT_OF_MEMORY),
409+
errmsg("out of memory")));
410+
return STATUS_ERROR;
411+
}
412+
snprintf(kt_path, kt_len, "KRB5_KTNAME=%s", pg_krb_server_keyfile);
406413
putenv(kt_path);
407414
}
408415
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy