You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously libpq would always error out if the server sends a
NegotiateProtocolVersion message. This was fine because libpq only
supported a single protocol version and did not support any protocol
parameters. But in the upcoming commits, we will introduce a new
protocol version and the NegotiateProtocolVersion message starts to
actually be used.
This patch modifies the client side checks to allow a range of
supported protocol versions, instead of only allowing the exact
version that was requested. Currently this "range" only contains the
3.0 version, but in a future commit we'll change this.
Also clarify the error messages, making them suitable for the world
where libpq will support multiple protocol versions and protocol
extensions.
Note that until the later commits that introduce new protocol version,
this change does not have any behavioural effect, because libpq will
only request version 3.0 and will never send protocol parameters, and
therefore will never receive a NegotiateProtocolVersion message from
the server.
Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Reviewed-by: Robert Haas <robertmhaas@gmail.com> (earlier versions)
Discussion: https://www.postgresql.org/message-id/CAGECzQTfc_O%2BHXqAo5_-xG4r3EFVsTefUeQzSvhEyyLDba-O9w@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAGECzQRbAGqJnnJJxTdKewTsNOovUt4bsx3NFfofz3m2j-t7tA@mail.gmail.com
* We don't currently request any protocol extensions, so we don't expect
1452
+
* the server to reply with any either.
1453
+
*/
1454
+
for (inti=0; i<num; i++)
1455
+
{
1456
+
if (pqGets(&conn->workBuffer, conn))
1457
+
{
1458
+
goto eof;
1459
+
}
1460
+
if (strncmp(conn->workBuffer.data, "_pq_.", 5) !=0)
1461
+
{
1462
+
libpq_append_conn_error(conn, "received invalid protocol negotiation message: server reported unsupported parameter name without a _pq_. prefix (\"%s\")", conn->workBuffer.data);
1463
+
goto failure;
1464
+
}
1465
+
libpq_append_conn_error(conn, "received invalid protocol negotiation message: server reported an unsupported parameter that was not requested (\"%s\")", conn->workBuffer.data);
1466
+
goto failure;
1467
+
}
1451
1468
1452
-
termPQExpBuffer(&buf);
1453
1469
return0;
1470
+
1471
+
eof:
1472
+
libpq_append_conn_error(conn, "received invalid protocol negotation message: message too short");
1473
+
failure:
1474
+
conn->asyncStatus=PGASYNC_READY;
1475
+
pqSaveErrorResult(conn);
1476
+
return1;
1454
1477
}
1455
1478
1456
1479
1457
1480
/*
1458
1481
* Attempt to read a ParameterStatus message.
1459
1482
* This is possible in several places, so we break it out as a subroutine.
1483
+
*
1460
1484
* Entry: 'S' message type and length have already been consumed.
1461
1485
* Exit: returns 0 if successfully consumed message.
0 commit comments