On 6/21/23 4:22 PM, Drouvot, Bertrand wrote:
Hi,

On 6/21/23 3:43 PM, Tom Lane wrote:
Kyotaro Horiguchi <horikyota....@gmail.com> writes:
At Wed, 21 Jun 2023 09:43:50 +0200, "Drouvot, Bertrand" 
<bertranddrouvot...@gmail.com> wrote in
Trying to connect with the 64 bytes name:
$ psql -d ääääääääääääääääääääääääääääääää
psql: error: connection to server on socket "/tmp/.s.PGSQL.55448"
failed: FATAL: database "äääääääääääääääääääääääääääääää" does not
exist

IMHO, I'm not sure we should allow connections without the exact name
being provided. In that sense, I think we might want to consider
outright rejecting the estblishment of a connection when the given
database name doesn't fit the startup packet, since the database with
the exact given name cannot be found.

I think I agree.  I don't like the proposed patch at all, because it's
making completely unsupportable assumptions about what encoding the
names are given in.  Simply failing to match when a name is overlength
sounds safer.


Yeah, that's another and "cleaner" option.

I'll propose a patch to make it failing even for the non multibyte case then (
so that multibyte and non multibyte behaves the same aka failing in case of 
overlength
name is detected).

Please find attached a patch doing so (which is basically a revert of 
d18c1d1f51).

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
From 1a40e13385752ef05b9602d1040e73dbb14d0c7e Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot...@gmail.com>
Date: Wed, 21 Jun 2023 18:28:13 +0000
Subject: [PATCH v1] Reject incoming username and database name in case of
 overlength

---
 src/backend/postmaster/postmaster.c | 9 ---------
 1 file changed, 9 deletions(-)
 100.0% src/backend/postmaster/

diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index 4c49393fc5..0b1de9efb2 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2290,15 +2290,6 @@ retry1:
                }
        }
 
-       /*
-        * 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
-- 
2.34.1

Reply via email to