Re: Incorrect usage of strtol, atoi for non-numeric junk inputs

Поиск
Список
Период
Сортировка
От Bharath Rupireddy
Тема Re: Incorrect usage of strtol, atoi for non-numeric junk inputs
Дата
Msg-id CALj2ACWddWd6Vms-MqhGdqcj6Z4V2qA9eUas1k4veb1yPF=dag@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Incorrect usage of strtol, atoi for non-numeric junk inputs  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Ответы Re: Incorrect usage of strtol, atoi for non-numeric junk inputs  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Список pgsql-hackers
On Thu, May 27, 2021 at 3:05 AM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>
> On 2021-May-19, Bharath Rupireddy wrote:
>
> > While working on [1], I found that some parts of the code is using
> > strtol and atoi without checking for non-numeric junk input strings. I
> > found this strange. Most of the time users provide proper numeric
> > strings but there can be some scenarios where these strings are not
> > user-supplied but generated by some other code which may contain
> > non-numeric strings. Shouldn't the code use strtol or atoi
> > appropriately and error out in such cases?  One way to fix this once
> > and for all is to have a common API something like int
> > pg_strtol/pg_str_convert_to_int(char *opt_name, char *opt_value) which
> > returns a generic message upon invalid strings ("invalid value \"%s\"
> > is provided for option \"%s\", opt_name, opt_value) and returns
> > integers on successful parsing.
>
> Hi, how is this related to
> https://postgr.es/m/20191028012000.GA59064@begriffs.com ?

Thanks. The proposed approach there was to implement postgres's own
strtol i.e. string parsing, conversion to integers and use it in the
places where atoi is being used. I'm not sure how far that can go.
What I'm proposing here is to use strtol inplace of atoi to properly
detect errors in case of inputs like '1211efe', '-14adc' and so on as
atoi can't detect such errors. Thoughts?

With Regards,
Bharath Rupireddy.



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

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: Race condition in recovery?
Следующее
От: Ranier Vilela
Дата:
Сообщение: Re: Parallel scan with SubTransGetTopmostTransaction assert coredump