Re: Increase psql's password buffer size

From: David Fetter <david(at)fetter(dot)org>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Increase psql's password buffer size
Date: 2020-01-22 00:41:04
Message-ID: 20200122004103.GE32763@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 21, 2020 at 07:05:47PM +0100, David Fetter wrote:
> 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)

[and unworkable]

I should have tested the code, but my point about using rep?alloc()
remains.

Best,
David.

Working code:

int main(int argc, char **argv)
{
size_t my_size = 2,
curr_size = 0;
char *buf;
int c;

buf = (char *) malloc(my_size);

printf("Enter a nice, long string.\n");

while( (c = getchar()) != '\0' )
{
buf[curr_size++] = c;
if (curr_size == my_size)
{
my_size *= 2;
buf = (char *) realloc(buf, my_size);
}
}
printf("The string %s is %zu bytes long.\n", buf, curr_size);
}
--
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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Karl O. Pinc 2020-01-22 01:03:38 Re: Patch to document base64 encoding
Previous Message Robert Haas 2020-01-22 00:23:56 Re: making the backend's json parser work in frontend code