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

Commit5bace41

Browse files
committed
Fix handling of escape sequences in postgres_fdw.application_name
postgres_fdw.application_name relies on MyProcPort to define the datathat should be added to escape sequences %u (user name) or %d (databasename). However this code could be run in processes that lack aMyProcPort, like an autovacuum process, causing crashes.The code generating the application name is made more flexible with thiscommit, so as it now generates no data for %u and %d if MyProcPort ismissing, and a simple "unknown" if MyProcPort exists, but the expectedfields are not set.Reported-by: Alexander LakhinAuthor: Kyotaro Horiguchi, Michael PaquierReviewed-by: Hayato Kuroda, Masahiko SawadaDiscussion:https://postgr.es/m/17789-8b31c5a4672b74d9@postgresql.orgBackpatch-through: 15
1 parent108a22b commit5bace41

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

‎contrib/postgres_fdw/option.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ process_pgfdw_appname(const char *appname)
461461
constchar*p;
462462
StringInfoDatabuf;
463463

464-
Assert(MyProcPort!=NULL);
465-
466464
initStringInfo(&buf);
467465

468466
for (p=appname;*p!='\0';p++)
@@ -498,13 +496,29 @@ process_pgfdw_appname(const char *appname)
498496
appendStringInfoString(&buf,cluster_name);
499497
break;
500498
case'd':
501-
appendStringInfoString(&buf,MyProcPort->database_name);
499+
if (MyProcPort)
500+
{
501+
constchar*dbname=MyProcPort->database_name;
502+
503+
if (dbname)
504+
appendStringInfoString(&buf,dbname);
505+
else
506+
appendStringInfoString(&buf,"[unknown]");
507+
}
502508
break;
503509
case'p':
504510
appendStringInfo(&buf,"%d",MyProcPid);
505511
break;
506512
case'u':
507-
appendStringInfoString(&buf,MyProcPort->user_name);
513+
if (MyProcPort)
514+
{
515+
constchar*username=MyProcPort->user_name;
516+
517+
if (username)
518+
appendStringInfoString(&buf,username);
519+
else
520+
appendStringInfoString(&buf,"[unknown]");
521+
}
508522
break;
509523
default:
510524
/* format error - ignore it */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp