Skip to content

Commit 48a2cd3

Browse files
committed
psql: fix startup crash caused by PSQLRC containing a tilde
'strdup' the PSQLRC environment variable value before calling a routine that might free() it. Backpatch to 9.2, where the bug first appeared.
1 parent bf2b0a1 commit 48a2cd3

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/bin/psql/common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,11 +1645,11 @@ session_username(void)
16451645
* substitute '~' with HOME or '~username' with username's home dir
16461646
*
16471647
*/
1648-
char *
1648+
void
16491649
expand_tilde(char **filename)
16501650
{
16511651
if (!filename || !(*filename))
1652-
return NULL;
1652+
return;
16531653

16541654
/*
16551655
* WIN32 doesn't use tilde expansion for file names. Also, it uses tilde
@@ -1697,5 +1697,5 @@ expand_tilde(char **filename)
16971697
}
16981698
#endif
16991699

1700-
return *filename;
1700+
return;
17011701
}

src/bin/psql/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ extern bool is_superuser(void);
4444
extern bool standard_strings(void);
4545
extern const char *session_username(void);
4646

47-
extern char *expand_tilde(char **filename);
47+
extern void expand_tilde(char **filename);
4848

4949
#endif /* COMMON_H */

src/bin/psql/startup.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,20 +610,21 @@ process_psqlrc(char *argv0)
610610
char rc_file[MAXPGPATH];
611611
char my_exec_path[MAXPGPATH];
612612
char etc_path[MAXPGPATH];
613-
char *envrc;
613+
char *envrc = getenv("PSQLRC");
614614

615615
find_my_exec(argv0, my_exec_path);
616616
get_etc_path(my_exec_path, etc_path);
617617

618618
snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
619619
process_psqlrc_file(rc_file);
620620

621-
envrc = getenv("PSQLRC");
622-
623621
if (envrc != NULL && strlen(envrc) > 0)
624622
{
625-
expand_tilde(&envrc);
626-
process_psqlrc_file(envrc);
623+
/* might need to free() this */
624+
char *envrc_alloc = pstrdup(envrc);
625+
626+
expand_tilde(&envrc_alloc);
627+
process_psqlrc_file(envrc_alloc);
627628
}
628629
else if (get_home_path(home))
629630
{

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