Re: Error in PQsetvalue

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Pavel Golub <pavel(at)microolap(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Error in PQsetvalue
Date: 2011-06-03 20:37:49
Message-ID: BANLkTikL8a0qoXZM-5UkqgOe=HoOvif1KQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 3, 2011 at 3:06 PM, Andrew Chernow <ac(at)esilo(dot)com> wrote:
> On 6/3/2011 3:03 PM, Pavel Golub wrote:
>>
>> Hello.
>>
>> Reproduced under Windows XP SP3 using Visual C++ 2008 and Delphi. If
>> PQsetvalue is called with second parameter equals to PQntuples then
>> memory corruption appears. But it should grow internal tuples array
>> and populate the last item with provided data. Please see the code:
>>
>>
>
> At first glance (have not tested this theory), looks like pqAddTuple()
> doesn't zero the newly allocated tuples slots like PQsetvalue() does.
> PQsetvalue is depending on the unassigned tuple table slots to be NULL to
> detect when a tuple must be allocated.  Around line 446 on fe-exec.c.  I
> never tested this case since libpqtypes never tried to call PQsetvalue on a
> PGresult created by the standard libpq library.
>
> The solution I see would be to zero the new table slots within pqAddTuple.
>  Any other ideas?

It might not be necessary to do that. AIUI the tuple table slot guard
is there essentially to let setval know if it needs to allocate tuple
attributes, which always has to be done after a new tuple is created
after a set. It should be enough to keep track of the 'allocation
tuple' as an int (which is incremented after attributes are allocated
for the new tuple). so if tup# is same is allocation tuple, allocate
the atts and increment the number, otherwise just do a straight 'set'.
Basically we are taking advantage of the fact only one tuple can be
allocated at a time, and it always has to be the next one after the
current set.

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Chernow 2011-06-03 20:38:27 Re: Error in PQsetvalue
Previous Message Bruce Momjian 2011-06-03 20:36:30 Re: Getting a bug tracker for the Postgres project