mirror of
https://github.com/postgres/postgres.git
synced 2025-06-08 22:02:03 +03:00
Fix handling of escape sequences in postgres_fdw.application_name
postgres_fdw.application_name relies on MyProcPort to define the data that should be added to escape sequences %u (user name) or %d (database name). However this code could be run in processes that lack a MyProcPort, like an autovacuum process, causing crashes. The code generating the application name is made more flexible with this commit, so as it now generates no data for %u and %d if MyProcPort is missing, and a simple "unknown" if MyProcPort exists, but the expected fields are not set. Reported-by: Alexander Lakhin Author: Kyotaro Horiguchi, Michael Paquier Reviewed-by: Hayato Kuroda, Masahiko Sawada Discussion: https://postgr.es/m/17789-8b31c5a4672b74d9@postgresql.org Backpatch-through: 15
This commit is contained in:
parent
108a22bd14
commit
5bace41abc
@ -461,8 +461,6 @@ process_pgfdw_appname(const char *appname)
|
|||||||
const char *p;
|
const char *p;
|
||||||
StringInfoData buf;
|
StringInfoData buf;
|
||||||
|
|
||||||
Assert(MyProcPort != NULL);
|
|
||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
|
|
||||||
for (p = appname; *p != '\0'; p++)
|
for (p = appname; *p != '\0'; p++)
|
||||||
@ -498,13 +496,29 @@ process_pgfdw_appname(const char *appname)
|
|||||||
appendStringInfoString(&buf, cluster_name);
|
appendStringInfoString(&buf, cluster_name);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
appendStringInfoString(&buf, MyProcPort->database_name);
|
if (MyProcPort)
|
||||||
|
{
|
||||||
|
const char *dbname = MyProcPort->database_name;
|
||||||
|
|
||||||
|
if (dbname)
|
||||||
|
appendStringInfoString(&buf, dbname);
|
||||||
|
else
|
||||||
|
appendStringInfoString(&buf, "[unknown]");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
appendStringInfo(&buf, "%d", MyProcPid);
|
appendStringInfo(&buf, "%d", MyProcPid);
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
appendStringInfoString(&buf, MyProcPort->user_name);
|
if (MyProcPort)
|
||||||
|
{
|
||||||
|
const char *username = MyProcPort->user_name;
|
||||||
|
|
||||||
|
if (username)
|
||||||
|
appendStringInfoString(&buf, username);
|
||||||
|
else
|
||||||
|
appendStringInfoString(&buf, "[unknown]");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* format error - ignore it */
|
/* format error - ignore it */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user