pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix broken list-munging in ecpg's remove_variables().
Date: Sun, 01 Dec 2024 19:16:05 +0000
Message-ID: <E1tHpQL-000csc-53@gemulon.postgresql.org> (raw)

Fix broken list-munging in ecpg's remove_variables().

The loops over cursor argument variables neglected to ever advance
"prevvar".  The code would accidentally do the right thing anyway
when removing the first or second list entry, but if it had to
remove the third or later entry then it would also remove all
entries between there and the first entry.  AFAICS this would
only matter for cursors that reference out-of-scope variables,
which is a weird Informix compatibility hack; between that and
the lack of impact for short lists, it's not so surprising that
nobody has complained.  Nonetheless it's a pretty obvious bug.

It would have been more obvious if these loops used a more standard
coding style for chasing the linked lists --- this business with the
"prev" pointer sometimes pointing at the current list entry is
confusing and overcomplicated.  So rather than just add a minimal
band-aid, I chose to rewrite the loops in the same style we use
elsewhere, where the "prev" pointer is NULL until we are dealing with
a non-first entry and we save the "next" pointer at the top of the
loop.  (Two of the four loops touched here are not actually buggy,
but it seems better to make them all look alike.)

Coverity discovered this problem, but not until 2b41de4a5 added code
to free no-longer-needed arguments structs.  With that, the incorrect
link updates are possibly touching freed memory, and it complained
about that.  Nonetheless the list corruption hazard is ancient, so
back-patch to all supported branches.

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e359cbb846788c584767288497beaa788a0f1b3e

Modified Files
--------------
src/interfaces/ecpg/preproc/variable.c | 67 +++++++++++++++++-----------------
1 file changed, 33 insertions(+), 34 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1tHpQL-000csc-53@gemulon.postgresql.org>
Permalink:  ../E1tHpQL-000csc-53@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tHpQL-000csc-53@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix broken list-munging in ecpg's remove_variables().
  In-Reply-To: <E1tHpQL-000csc-53@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox