Re: Oops in fe-auth.c

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Oops in fe-auth.c
Date: 2007-07-23 14:36:00
Message-ID: 20070723143600.GB4119@svr2.hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Mon, Jul 23, 2007 at 10:28:57AM -0400, Tom Lane wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
> > When run in debug mode, the runtime for msvc will *zero-pad the entire
> > buffer* in a strncpy() call. This in itself is not bad (just slow), but it
> > shows a rather bad bug in libpq.
>
> [squint] That is the specified behavior of strncpy on every platform,
> not only msvc. If there's a bug here why didn't we notice it long ago?

Hmm. Interesting - I see that now if I look at
http://www.opengroup.org/onlinepubs/007908799/xsh/strncpy.html.

That's very interesting - but my debugger very much shows me that the
buffer size is 256 bytes (INITIAL_EXPBUFFER_SIZE), and passes
1024 (PQERRORMSG_LENGTH) as the size of the buffer...

Perhaps we've just never hit one of those codepaths before. Previously, it
was only used for out of memory errors - the gssapi code adds a few places
where it's used in other cases, and this is where it crashed for me.

> > Given this, I'll go ahead and fix fe-connect to support PQExpBuffers,
> > unless there are any objections.
>
> I'm not against that, but I question what bug you've really found.

I never actually tested if it crashes on mingw, but looking some more at it
it really should - once one of these errors happen.

//Magnus

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-07-23 14:40:21 Re: Full page images in WAL & Cache Invalidation
Previous Message Tom Lane 2007-07-23 14:34:18 Re: SSPI vs MingW

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Dunstan 2007-07-23 15:26:27 Re: COPYable logs
Previous Message Tom Lane 2007-07-23 14:28:57 Re: Oops in fe-auth.c