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

Поиск
Список
Период
Сортировка
От Fujii Masao
Тема Re: [BUG FIX]Connection fails with whitespace after keepalives parameter value
Дата
Msg-id 22c1339a-2060-45d2-8744-45c9ebecbf5d@oss.nttdata.com
обсуждение исходный текст
Ответ на Re: [BUG FIX]Connection fails with whitespace after keepalives parameter value  (Fujii Masao <masao.fujii@oss.nttdata.com>)
Ответы Re: [BUG FIX]Connection fails with whitespace after keepalives parameter value
Список pgsql-hackers

On 2024/10/02 11:35, Michael Paquier wrote:
> On Tue, Oct 01, 2024 at 12:29:15PM -0400, Tom Lane wrote:
>> Fujii Masao <masao.fujii@oss.nttdata.com> writes:
>>> Is a connection URL with whitespace, like "tcp:postgresql://localhost:5432/postgres?keepalives=1 & ...",
>>> considered valid? If not, the issue seems to be that ecpg adds unnecessary whitespace
>>> to the connection URL, especially after the "&" character.
>>
>> I agree with Sasaki-san that useKeepalives seems rather bogus: almost
>> every other place in fe-connect.c uses pqParseIntParam rather than
>> calling strtol directly, so why not this one?

I have no objection to improving the handling of the keepalives parameter.
OTOH, I think ecpg might have an issue when converting the connection URI.


> Yes, it is a mistake to not use pqParseIntParam(), or
> parse_int_param() depending on the branch.  This stuff has been
> introduced by 4f4061b2dde1, where I've spent some time making sure
> that leading and trailing whitespaces are discarded in this routine.
> 
> See also these examples where whitespaces are OK in a connection URL:
> https://www.postgresql.org/message-id/20191021024020.GF1542%40paquier.xyz

For example, ecpg converts:

EXEC SQL CONNECT TO
tcp:postgresql://localhost:5432/postgres?keepalives=1&keepalives_idle=1&keepalives_interval=1&keepalives_count=2USER
postgres;

into:

{ ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost:5432/postgres?keepalives=1 & keepalives_idle=1 &
keepalives_interval=1& keepalives_count=2" , "postgres" , NULL , NULL, 0);
 


In the converted URI, whitespace is added before and after the ? character.
In my quick test, ECPGconnect() seems to handle this without error,
but when I tried the same URI in psql, it returned an error:

$ psql "postgresql://localhost:5432/postgres?keepalives=1 & keepalives_idle=1 & keepalives_interval=1 &
keepalives_count=2"
psql: error: invalid URI query parameter: " keepalives_idle"


It seems that libpq may consider this URI invalid.

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION




В списке pgsql-hackers по дате отправления: