From 78190176b20392fa2396731d4693ebe6286679c8 Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Mon, 5 May 2025 14:19:10 -0700 Subject: [PATCH v1 1/2] Fix connhost type during non-blocking cancellation PQcancelCreate() creates a deep copy of the connection's pg_conn_host, but it missed the type field, which ended up initialized to CHT_HOST_NAME. The type communicates which pointers in the struct are valid, so if a connection used hostaddr without a host name (which would normally result in a type of CHT_HOST_ADDRESS), the client would later segfault in emitHostIdentityInfo(). Backpatch to 17, where the new API was introduced. Reviewed-by: TODO Backpatch-through: 17 --- src/interfaces/libpq/fe-cancel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/interfaces/libpq/fe-cancel.c b/src/interfaces/libpq/fe-cancel.c index 25de2a337c9..9674d0a156b 100644 --- a/src/interfaces/libpq/fe-cancel.c +++ b/src/interfaces/libpq/fe-cancel.c @@ -137,6 +137,8 @@ PQcancelCreate(PGconn *conn) goto oom_error; originalHost = conn->connhost[conn->whichhost]; + cancelConn->connhost[0].type = originalHost.type; + if (originalHost.host) { cancelConn->connhost[0].host = strdup(originalHost.host); -- 2.34.1