Re: [BUG FIX]Connection fails with whitespace after keepalives parameter value

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Fujii Masao <masao.fujii@oss.nttdata.com>, "Yuto Sasaki (Fujitsu)" <sasaki.yuto-00@fujitsu.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2024-10-03T00:42:00Z
Lists: pgsql-hackers

Attachments

On Wed, Oct 02, 2024 at 05:39:31PM -0400, Tom Lane wrote:
> Interesting.  This is unhappy about the space before a parameter name,
> not the space after a parameter value, so it's a different issue.

conninfo_uri_parse_options() parses the URI as a set of option/values,
where conninfo_uri_parse_params.  If we were to be careful about
trailing and leading whitespaces for the parameter names, we need to
be careful about the special JDBC cases for "ssl" and "requiressl",
meaning that we should add more logic in conninfo_uri_decode() to
discard these.  That would apply a extra layer of sanity into the
values as well.

> But it's weird that ecpg takes it while libpq doesn't.  Could libecpg
> be modifying/reassembling the URI string?  I didn't look.

ECPGconnect() has some custom logic to discard trailing and leading
spaces: 
    /* Skip spaces before keyword */
    for (token1 = str; *token1 == ' '; token1++)
[...]
    token1[e] = '\0'; //skips trailing spaces.

The argument for libpq where we could be consistent is appealing.  How
about lifting things in libpq like the attached?  I wouldn't backpatch
that, but we have tests for URIs and I didn't break anything.
--
Michael

Commits

  1. libpq: Discard leading and trailing spaces for parameters and values in URIs

  2. ecpg: avoid adding whitespace around '&' in connection URLs.

  3. Parse libpq's "keepalives" option more like other integer options.