Skip to content

Commit d09fbf6

Browse files
Revert "Don't truncate database and user names in startup packets."
This reverts commit 562bee0. We received a report from the field about this change in behavior, so it seems best to revert this commit and to add proper multibyte-aware truncation as a follow-up exercise. Fixes bug #18711. Reported-by: Adam Rauch Reviewed-by: Tom Lane, Bertrand Drouvot, Bruce Momjian, Thomas Munro Discussion: https://postgr.es/m/18711-7503ee3e449d2c47%40postgresql.org Backpatch-through: 17
1 parent 8afff7d commit d09fbf6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/backend/tcop/backend_startup.c

+9
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,15 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
805805
if (port->database_name == NULL || port->database_name[0] == '\0')
806806
port->database_name = pstrdup(port->user_name);
807807

808+
/*
809+
* Truncate given database and user names to length of a Postgres name.
810+
* This avoids lookup failures when overlength names are given.
811+
*/
812+
if (strlen(port->database_name) >= NAMEDATALEN)
813+
port->database_name[NAMEDATALEN - 1] = '\0';
814+
if (strlen(port->user_name) >= NAMEDATALEN)
815+
port->user_name[NAMEDATALEN - 1] = '\0';
816+
808817
if (am_walsender)
809818
MyBackendType = B_WAL_SENDER;
810819
else

0 commit comments

Comments
 (0)