Re: postgres_fdw can crash on malformed remote results

From: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
To: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Subject: Re: postgres_fdw can crash on malformed remote results
Date: 2026-12-03 15:47:28
Message-ID: CADkLM=eLr2Armn-oqwprUoNwOc73Lu28zOMqQOTSfcvNnrdCgw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Dec 2, 2026 at 4:47 AM Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
wrote:

> Hi,
>
> On Wed, 2 Dec 2026 at 08:59, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> >
> > On Wed, Dec 2, 2026 at 4:10 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
> wrote:
> > > It's a trivial and lightweight fix, with cited precedent for making
> the same change, applies clean and passes tests.
> >
> > +1
> >
> > + if (PQntuples(res) < 1 || PQnfields(res) < 1)
> > + elog(ERROR, "unexpected result from remote EXPLAIN command");
> >
> > Since EXPLAIN always returns one column, isn't it better to use
> > "PQnfields(res) != 1", consistent with the "PQnfields(res) != 8" check
> > for IMPORT FOREIGN SCHEMA?
>
> Ahh makes sense, done that way in v2.
>

+1 to that change as well.

> For Corey:
>
> The fake server I used was put together by hand, but the attached
> Python script (generated with Codex) roughly simulates it, in case it's
> useful.
>

Something like this would be promising if it could be integrated int TAP
tests. Instead of sending valid SQL, the client could send the name of the
response scenario it wanted to receive. This might be a cheap way to
enhance test coverage, but we can discuss that in another thread. Thanks!

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-12-03 16:01:34 add --transfer-mode to pg_upgrade
Previous Message Jan Nidzwetzki 2026-12-03 15:36:56 Re: Standby writes pages past minRecoveryPoint after crash recovery