Re: Incorrect usage of strtol, atoi for non-numeric junk inputs
Kyotaro Horiguchi <horikyota.ntt@gmail.com>
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
To: bharath.rupireddyforpostgres@gmail.com
Cc: alvherre@alvh.no-ip.org, pgsql-hackers@lists.postgresql.org
Date: 2021-07-08T08:30:23Z
Lists: pgsql-hackers
Attachments
- 0001-Be-strict-in-numeric-parameters-on-command-line.patch (text/x-patch)
At Wed, 7 Jul 2021 17:40:13 +0530, Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote in > On Fri, Jun 4, 2021 at 10:23 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote: > > > > On 2021-Jun-04, Bharath Rupireddy wrote: > > > > > On Fri, Jun 4, 2021 at 8:58 PM Alvaro Herrera <alvherre@alvh.no-ip.org> wrote: > > > > > > I would suggest that the best way forward in this area is to rebase both > > > > there patches on current master. > > > > > > Thanks. I will read both the threads [1], [2] and try to rebase the > > > patches. If at all I get to rebase them, do you prefer the patches to > > > be in this thread or in a new thread? > > > > Thanks, that would be helpful. This thread is a good place. > > I'm unable to spend time on this work as promised. I'd be happy if > someone could take it forward, although it's not critical work(IMO) > that needs immediate focus. I will try to spend time maybe later this > year. Looked through the three threads. [1] is trying to expose pg_strtoint16/32 to frontend, but I don't see much point in doing that in conjunction with [2] or this thread. Since the integral parameter values of pg-commands are in int, which the exising function strtoint() is sufficient to read. So even [2] itself doesn't need to utilize [1]. So I agree to the Bharath's point. So the attached is a standalone patch that: - doesn't contain [1], since that functions are not needed for this purpose. - basically does the same thing with [2], but uses strtoint/strtol/strtod instead of pg_strtoint16/32. - doesn't try to make error messages verbose. That results in a somewhat strange message like this but I'm not sure we should be so strict at that point. > reindexdb: error: number of parallel jobs must be at least 1: hoge - is extended to cover all usages of atoi/l/f in command line processing, which are not fully covered by [2]. (Maybe) - is extended to cover psql's meta command parameters. - is extended to cover integral environment variables. (PGPORTOLD/NEW of pg_upgrade and COLUMNS of psql). The commands emit a warning for invalid values, but I'm not sure it's worthwhile. (The second attached.) > psql: warning: ignored invalid setting of environemt variable COLUMNS: 3x - doesn't cover pgbench's meta command parameters (for speed). [1] - https://www.postgresql.org/message-id/flat/alpine.DEB.2.21.1904201223040.29102@lancre [2] - https://www.postgresql.org/message-id/20191028012000.GA59064@begriffs.com regards. -- Kyotaro Horiguchi NTT Open Source Software Center
Commits
-
Simplify matching pattern check in TAP tests of pg_receivewal
- 24ba1a87e405 15.0 landed
-
Skip trailing whitespaces when parsing integer options
- f7a9a3d4b24a 15.0 landed
-
Unify parsing logic for command-line integer options
- 6f164e6d1761 15.0 landed