Re: Increase psql's password buffer size - Mailing list pgsql-hackers

From David Fetter
Subject Re: Increase psql's password buffer size
Date
Msg-id 20200121180547.GC32763@fetter.org
Whole thread Raw
In response to Re: Increase psql's password buffer size  (Bruce Momjian <bruce@momjian.us>)
Responses Re: Increase psql's password buffer size  (David Fetter <david@fetter.org>)
List pgsql-hackers
On Tue, Jan 21, 2020 at 10:23:59AM -0500, Bruce Momjian wrote:
> On Tue, Jan 21, 2020 at 04:19:13PM +0100, David Fetter wrote:
> > On Tue, Jan 21, 2020 at 10:12:52AM -0500, Bruce Momjian wrote:
> > > I think we should be using a macro to define the maximum length, rather
> > > than have 100 used in various places.
> > 
> > It's not just 100 in some places. It's different in different places,
> > which goes to your point.
> > 
> > How about using a system that doesn't meaningfully impose a maximum
> > length? The shell variable is a const char *, so why not just
> > re(p)alloc as needed?
> 
> Uh, how do you know how big to make the buffer that receives the read?

You can start at any size, possibly even 100, and then increase the
size in a loop along the lines of (untested)

my_size = 100;
my_buf = char[my_size];
curr_size = 0;
while (c = getchar() != '\0')
{
    my_buf[curr_size++] = c;
    if (curr_size == my_size) /* If we want an absolute maximum,
                                 this'd be the place to test for it.
                                 */
    {
        my_size *= 2;
        repalloc(my_buf, my_size);
    }
}

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Removing pg_pltemplate and creating "trustable" extensions
Next
From: Alvaro Herrera
Date:
Subject: Re: Protect syscache from bloating with negative cache entries