ecpg: fix ECPGstore_input()

From: Neil Conway <neilc(at)samurai(dot)com>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: ecpg: fix ECPGstore_input()
Date: 2005-07-06 15:45:53
Message-ID: 42CBFCB1.9050405@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

This patch fixes the following issues in ECPGstore_input():

- strlen() was invoked on the NULL pointer for the first iteration of
the loop (line 875, 923, 966, 1009)

- `nval' is freed for every iteration of the loop at 864, but only
initialized once outside the loop, resulting in potential multiple
free()'s, as well as the use of a freed variable in subsequent iterations

- `str' was leaked for every subsequent iteration of the loop (line 871,
920, 963, 1006)

- the return value of PGTYPESinterval_to_asc() is leaked at line 920 and
937; the return value of PGTYPESdate_to_asc() is leaked at line 963 and
980; the return value of PGTYPEStimestamp_to_asc() is leaked at line
1006 and 1023.

- malloc failure is in general not handled well; the function simply
returns without bothering to clean up allocated resources, and many
return values are not checked for errors.

Also, in create_statement(), `*stmt' was dereferenced before being
initialized.

Per the Coverity report run by EnterpriseDB. Thanks to Eric Astor at EDB
for an initial version of this patch -- the attached version has been
improved by myself.

Barring any objections, I'd like to apply this to CVS in a day or two (I
want to test it first, which I haven't yet done).

-Neil

Attachment Content-Type Size
ecpg_execute_ecpgstore_input_fix-3.patch text/x-patch 15.1 KB

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Dunstan 2005-07-06 15:50:51 plperl SRF sanity check fix
Previous Message Neil Conway 2005-07-06 15:20:13 Re: User's exception plpgsql