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

Commit48a2cd3

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 parentbf2b0a1 commit48a2cd3

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-
returnNULL;
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
externboolstandard_strings(void);
4545
externconstchar*session_username(void);
4646

47-
externchar*expand_tilde(char**filename);
47+
externvoidexpand_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
charrc_file[MAXPGPATH];
611611
charmy_exec_path[MAXPGPATH];
612612
charetc_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
elseif (get_home_path(home))
629630
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp