Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: adam(at)labkey(dot)com, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails
Date: 2024-11-19 22:50:36
Message-ID: Zz0WPCEzx-mPvUxA@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Nov 19, 2024 at 02:33:27PM -0500, Tom Lane wrote:
> I did think of a way that we could approximate encoding-correct
> truncation here, relying on the fact that what's in pg_database
> is encoding-correct according to somebody:
>
> 1. If NAMEDATALEN-1'th byte is ASCII (high bit clear), just truncate
> there and look up as usual.
>
> 2. If it's non-ASCII, truncate there and try to look up. On success,
> we're good. On failure, if the next-to-last byte is non-ASCII,
> truncate that too and try to look up. Repeat a maximum of
> MAX_MULTIBYTE_CHAR_LEN-1 times before failing.
>
> I think this works unconditionally so long as all entries in
> pg_database.datname are in the same encoding. If there's a
> mixture of encodings (which we don't forbid) then in principle
> you could probably select a database other than the one the
> client thought it was asking for. But that seems mighty
> improbable, and the answer can always be "so connect using
> the name as it appears in the catalog".

That's an interesting idea. That code would probably need to live in
GetDatabaseTuple(), but it seems doable. We might be able to avoid the
"mighty improbable" case by always truncating up to
MAX_MULTIBYTE_CHAR_LEN-1 times and failing if there are multiple matches,
too.

--
nathan

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-11-19 23:09:44 Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails
Previous Message Tom Lane 2024-11-19 22:40:48 Re: BUG #18715: replace() function silently fails if 3rd argument is null