Re: psql - add SHOW_ALL_RESULTS option

Andres Freund <andres@anarazel.de>

From: Andres Freund <andres@anarazel.de>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2022-01-13T05:44:33Z
Lists: pgsql-hackers
Hi,

On 2022-01-08 19:32:36 +0100, Fabien COELHO wrote:
> Attached v13 where the crash test is moved to tap.

The reason this test constantly fails on cfbot windows is a use-after-free
bug.

I figured that out in the context of another thread, so the debugging is
there:

https://postgr.es/m/20220113054123.ib4khtafgq34lv4z%40alap3.anarazel.de
> Ah, I see the bug. It's a use-after-free introduced in the patch:
>
> SendQueryAndProcessResults(const char *query, double *pelapsed_msec,
> 	bool is_watch, const printQueryOpt *opt, FILE *printQueryFout, bool *tx_ended)
> 
> 
> ...
> 	/* first result */
> 	result = PQgetResult(pset.db);
> 
> 
> 	while (result != NULL)
> 
> 
> ...
> 		if (!AcceptResult(result, false))
> 		{
> ...
> 			ClearOrSaveResult(result);
> 			success = false;
> 
> 
> 			/* and switch to next result */
> 			result_status = PQresultStatus(result);
> 			if (result_status == PGRES_COPY_BOTH ||
> 				result_status == PGRES_COPY_OUT ||
> 				result_status == PGRES_COPY_IN)
> 
> 
> So we called ClearOrSaveResult() with did a PQclear(), and then we go and call
> PQresultStatus().

Greetings,

Andres Freund



Commits

  1. psql: Show all query results by default

  2. psql: Refactor ProcessResult()

  3. psql: Refactor SendQuery()

  4. psql: Add test for psql behavior on server crash

  5. psql: Additional tests

  6. Improve some psql test code

  7. psql: Fix some scan-build warnings

  8. psql: Add test for handling of replication commands

  9. psql: More tests

  10. psql: Add various tests

  11. psql: Add test for query canceling

  12. Revert "psql: Show all query results by default"

  13. Extend a test case a little