libpq: Be strict about cancel key lengths
authorHeikki Linnakangas <[email protected]>
Fri, 22 Aug 2025 11:39:29 +0000 (14:39 +0300)
committerHeikki Linnakangas <[email protected]>
Fri, 22 Aug 2025 11:39:29 +0000 (14:39 +0300)
commite411a8d25a4b39e5a896f765ca91636057e261fc
tree58904b5f1f6358df79a5a5b17b6ba8d2b1ebbcbf
parentf6f0542266f0a04e94ac2a67ae6890d6095101ab
libpq: Be strict about cancel key lengths

The protocol documentation states that the maximum length of a cancel
key is 256 bytes. This starts checking for that limit in libpq.
Otherwise third party backend implementations will probably start
using more bytes anyway. We also start requiring that a protocol 3.0
connection does not send a longer cancel key, to make sure that
servers don't start breaking old 3.0-only clients by accident. Finally
this also restricts the minimum key length to 4 bytes (both in the
protocol spec and in the libpq implementation).

Author: Jelte Fennema-Nio <[email protected]>
Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/df892f9f-5923-4046-9d6f-8c48d8980b50@iki.fi
Backpatch-through: 18
doc/src/sgml/protocol.sgml
src/interfaces/libpq/fe-protocol3.c