Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite7ff968

Browse files
committed
libpq: Be strict about cancel key lengths
The protocol documentation states that the maximum length of a cancelkey is 256 bytes. This starts checking for that limit in libpq.Otherwise third party backend implementations will probably startusing more bytes anyway. We also start requiring that a protocol 3.0connection does not send a longer cancel key, to make sure thatservers don't start breaking old 3.0-only clients by accident. Finallythis also restricts the minimum key length to 4 bytes (both in theprotocol spec and in the libpq implementation).Author: Jelte Fennema-Nio <postgres@jeltef.nl>Reviewed-by: Jacob Champion <jchampion@postgresql.org>Discussion:https://www.postgresql.org/message-id/df892f9f-5923-4046-9d6f-8c48d8980b50@iki.fiBackpatch-through: 18
1 parent8aa287c commite7ff968

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎doc/src/sgml/protocol.sgml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4163,7 +4163,7 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
41634163
message, indicated by the length field.
41644164
</para>
41654165
<para>
4166-
The maximum key lengthis256 bytes. The
4166+
Theminimum andmaximum key lengthare 4 and256 bytes, respectively. The
41674167
<productname>PostgreSQL</productname> server only sends keys up to
41684168
32 bytes, but the larger maximum size allows for future server
41694169
versions, as well as connection poolers and other middleware, to use

‎src/interfaces/libpq/fe-protocol3.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,27 @@ getBackendKeyData(PGconn *conn, int msgLength)
15691569

15701570
cancel_key_len=5+msgLength- (conn->inCursor-conn->inStart);
15711571

1572+
if (cancel_key_len!=4&&conn->pversion==PG_PROTOCOL(3,0))
1573+
{
1574+
libpq_append_conn_error(conn,"received invalid BackendKeyData message: cancel key with length %d not allowed in protocol version 3.0 (must be 4 bytes)",cancel_key_len);
1575+
handleFatalError(conn);
1576+
return0;
1577+
}
1578+
1579+
if (cancel_key_len<4)
1580+
{
1581+
libpq_append_conn_error(conn,"received invalid BackendKeyData message: cancel key with length %d is too short (minimum 4 bytes)",cancel_key_len);
1582+
handleFatalError(conn);
1583+
return0;
1584+
}
1585+
1586+
if (cancel_key_len>256)
1587+
{
1588+
libpq_append_conn_error(conn,"received invalid BackendKeyData message: cancel key with length %d is too long (maximum 256 bytes)",cancel_key_len);
1589+
handleFatalError(conn);
1590+
return0;
1591+
}
1592+
15721593
conn->be_cancel_key=malloc(cancel_key_len);
15731594
if (conn->be_cancel_key==NULL)
15741595
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp