Fix libpq crashes on malformed target_session_attrs query results Applications using libpq could crash during connection establishment when a server returned an unexpected result for an internal query used to check target_session_attrs.
This happened because libpq checked that the result contained one row, but did not check the column count before reading the first column. A result with one row and no columns caused PQgetvalue() to return NULL, which was then passed to strncmp(). Fix this by requiring exactly one column in the results of SHOW transaction_read_only and SELECT pg_catalog.pg_is_in_recovery(). Malformed results now follow the existing error path, rejecting the connection attempt to that host and trying the next host, if any. Backpatch to all supported versions. Author: s1ko <[email protected]> Reviewed-by: Chao Li <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/42fa657db316e033ca5b30a4ac0bf69835b70ab8 Modified Files -------------- src/interfaces/libpq/fe-connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
