Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39d4c76

Browse files
committed
psql: fix startup crash caused by PSQLRC containing a tilde
'strdup' the PSQLRC environment variable value before calling a routinethat might free() it.Backpatch to 9.2, where the bug first appeared.
1 parentc99e0d3 commit39d4c76

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
@@ -1617,11 +1617,11 @@ session_username(void)
16171617
* substitute '~' with HOME or '~username' with username's home dir
16181618
*
16191619
*/
1620-
char*
1620+
void
16211621
expand_tilde(char**filename)
16221622
{
16231623
if (!filename|| !(*filename))
1624-
returnNULL;
1624+
return;
16251625

16261626
/*
16271627
* WIN32 doesn't use tilde expansion for file names. Also, it uses tilde
@@ -1669,5 +1669,5 @@ expand_tilde(char **filename)
16691669
}
16701670
#endif
16711671

1672-
return*filename;
1672+
return;
16731673
}

‎src/bin/psql/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ extern bool is_superuser(void);
6161
externboolstandard_strings(void);
6262
externconstchar*session_username(void);
6363

64-
externchar*expand_tilde(char**filename);
64+
externvoidexpand_tilde(char**filename);
6565

6666
#endif/* COMMON_H */

‎src/bin/psql/startup.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,20 +591,21 @@ process_psqlrc(char *argv0)
591591
charrc_file[MAXPGPATH];
592592
charmy_exec_path[MAXPGPATH];
593593
charetc_path[MAXPGPATH];
594-
char*envrc;
594+
char*envrc=getenv("PSQLRC");
595595

596596
find_my_exec(argv0,my_exec_path);
597597
get_etc_path(my_exec_path,etc_path);
598598

599599
snprintf(rc_file,MAXPGPATH,"%s/%s",etc_path,SYSPSQLRC);
600600
process_psqlrc_file(rc_file);
601601

602-
envrc=getenv("PSQLRC");
603-
604602
if (envrc!=NULL&&strlen(envrc)>0)
605603
{
606-
expand_tilde(&envrc);
607-
process_psqlrc_file(envrc);
604+
/* might need to free() this */
605+
char*envrc_alloc=pg_strdup(envrc);
606+
607+
expand_tilde(&envrc_alloc);
608+
process_psqlrc_file(envrc_alloc);
608609
}
609610
elseif (get_home_path(home))
610611
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp