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 when the server returns a
NegotiateProtocolVersion message. This was fine because libpq only
supported a single protocol version and did not support any protocol
parameters. But we now that we're discussing protocol changes we need
to change this behaviour, and introduce a fallback mechanism when
connecting to an older server.
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. In addition it
changes the errors for protocol to say that they error because we did
not request any parameters, not because the server did not support
some of them. In a future commit more infrastructure for protocol
parameters will be added, so that these checks can also succeed when
receiving unsupported parameters back.
Note that at the moment this change does not have any behavioural
effect, because libpq will only request version 3.0 and will never
send protocol parameters. Which means that the client never receives a
NegotiateProtocolVersion message from the server.
Author: Jelte Fennema-Nio <[email protected]>
Discussion: https://www.postgresql.org/message-id/CAGECzQTfc_O%[email protected]
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