diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-12-12 15:52:04 -0600 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-12-12 15:52:04 -0600 |
commit | a0ff56e2d3ff1db3de727b33b2dac985ccc43ef8 (patch) | |
tree | ac43d0200ea5f91a2128589e7caf1d2bcb3e5669 | |
parent | 4766438aa317e85f3d762847b2b009f91f530b6f (diff) | |
download | postgresql-a0ff56e2d3ff1db3de727b33b2dac985ccc43ef8.tar.gz postgresql-a0ff56e2d3ff1db3de727b33b2dac985ccc43ef8.zip |
Revert "Don't truncate database and user names in startup packets."
This reverts commit 562bee0fc13dc95710b8db6a48edad2f3d052f2e.
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
-rw-r--r-- | src/backend/tcop/backend_startup.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c index 2a96c81f925..5e9ad30aebc 100644 --- a/src/backend/tcop/backend_startup.c +++ b/src/backend/tcop/backend_startup.c @@ -830,6 +830,15 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done) if (port->database_name == NULL || port->database_name[0] == '\0') port->database_name = pstrdup(port->user_name); + /* + * Truncate given database and user names to length of a Postgres name. + * This avoids lookup failures when overlength names are given. + */ + if (strlen(port->database_name) >= NAMEDATALEN) + port->database_name[NAMEDATALEN - 1] = '\0'; + if (strlen(port->user_name) >= NAMEDATALEN) + port->user_name[NAMEDATALEN - 1] = '\0'; + if (am_walsender) MyBackendType = B_WAL_SENDER; else |