Re: Unlikely-to-happen crash in ecpg driver caused by NULL-pointer check not done - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Unlikely-to-happen crash in ecpg driver caused by NULL-pointer check not done
Date
Msg-id CAB7nPqS-oWUbRjPwzFm9WtEK0j-6pVvHT=hTErBh56tDdn=-rQ@mail.gmail.com
Whole thread Raw
In response to Re: Unlikely-to-happen crash in ecpg driver caused by NULL-pointer check not done  (Heikki Linnakangas <hlinnakangas@vmware.com>)
Responses Re: Unlikely-to-happen crash in ecpg driver caused by NULL-pointer check not done  (Michael Meskes <meskes@postgresql.org>)
List pgsql-hackers
On Tue, Feb 3, 2015 at 7:50 PM, Heikki Linnakangas
<hlinnakangas@vmware.com> wrote:
> Hmm. Since the ecpg_add_mem call is done after setting (*(void **) var),
> that's left to point to already-free'd memory. The other call sites have a
> similar issue. I haven't analyzed the code to check if that's harmless or
> not, but seems better to not do that.
Right, it is an error do allocate this memory if there is a risk that
it may be freed. Hence fixed.

> In ecpg_add_mem, the ecpg_raise() call is unnecessary, since ecpg_alloc
> already does that on failure.
Right, check.

> (It would be less error-prone to have an ecpg_alloc_auto() function that
> combines ecpg_alloc+ecpg_add_mem in one call.)
It makes sense.

>> /* Here are some methods used by the lib. */
>>
>> /* Returns a pointer to a string containing a simple type name. */

> That second comment is completely bogus. It's not this patch's fault, it's
> been like that forever, but just happened to notice..
Corrected.

All those things are addressed in the patch attached.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Petr Jelinek
Date:
Subject: Re: Getting rid of wal_level=archive and default to hot_standby + wal_senders
Next
From: Kevin Grittner
Date:
Subject: Re: Release note bloat is getting out of hand