Re: PSQL schema "describe" \dn is not escaping quotes

From: Steven Niu <niushiji(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>, Ajin Cherian <itsajin(at)gmail(dot)com>
Cc: surya poondla <suryapoondla4(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "jiaoshuntian(at)gmail(dot)com" <jiaoshuntian(at)gmail(dot)com>, "nishant(dot)sharma(at)enterprisedb(dot)com" <nishant(dot)sharma(at)enterprisedb(dot)com>, "jim(dot)jones(at)uni-muenster(dot)de" <jim(dot)jones(at)uni-muenster(dot)de>
Subject: Re: PSQL schema "describe" \dn is not escaping quotes
Date: 2026-09-24 05:39:17
Message-ID: EAYPR19MB481711EF77CA18B172C52870DEA7812@EAYPR19MB481711.namprd19.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Peter,

I have two comments for V6 patch:

1. In function describeOneSchemaDetails(), res gets assigned by PSQLexec(),
if res is NULL, code flow goes to error_return label where termPQExpBuffer(&title) is called.

However, the title is NOT initialized at all in this case.
Suggest to initialize the title right after the initialization of buf.

2. Also in function describeOneSchemaDetails(), res gets assigned by PSQLexec();

res = PSQLexec(buf.data);

If the PQclear() is successful, we will go inside the Footer processing,
if pset.sversion >= 150000 and following PSQLexec() fails,

result = PSQLexec(buf.data);
if (!result)
goto error_return;

code flow goes to error_return label. But there is no PQclear(res), and I think it may cause memory leak;
Suggest to initialize the res to be NULL and add PQclear(res) in error_return branch.

Thanks,
Steven

________________________________________
From: Peter Smith <smithpb2250(at)gmail(dot)com>
Sent: Friday, September 11, 2026 15:55
To: Ajin Cherian <itsajin(at)gmail(dot)com>
Cc: surya poondla <suryapoondla4(at)gmail(dot)com>; PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>; jiaoshuntian(at)gmail(dot)com <jiaoshuntian(at)gmail(dot)com>; nishant(dot)sharma(at)enterprisedb(dot)com <nishant(dot)sharma(at)enterprisedb(dot)com>; jim(dot)jones(at)uni-muenster(dot)de <jim(dot)jones(at)uni-muenster(dot)de>; niushiji(at)gmail(dot)com <niushiji(at)gmail(dot)com>
Subject: Re: PSQL schema "describe" \dn is not escaping quotes

On Thu, Sep 10, 2026 at 7:52 PM Ajin Cherian <itsajin(at)gmail(dot)com> wrote:
>
...
> Thanks for the updated match with the fixes and the new tests. The fix
> works and the new tests are welcome. A few minor comments:
>
> 1.
> + for (int i = 0; i < num_schemas; i++)
> + {
> + const char *nspname = PQgetvalue(res, i, 0);
> +
> + describeOneSchemaDetails(nspname, verbose);
> + }
> + }
>
> The return value (bool) of  describeOneSchemaDetails is ignored. Is it
> even required?
>

The return was there to mirror the other describeOneXXX functions, but
I neglected to check it. Now handling the result, similar to other
functions.

> 2.
> The code now allocates memory for title as well but is not freed in
> the error path.
>
> + initPQExpBuffer(&title);
> + printfPQExpBuffer(&title, _("Schema \"%s\""), schemaname);
>

Fixed.

PSA patch v6.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-09-24 06:05:52 Re: ERROR: failed to find conversion function from unknown to text
Previous Message Bertrand Drouvot 2026-09-24 05:27:26 Re: Add a permission check to pg_stat_get_backend_subxact()