mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Use pg_parse_lsn() for IDENTIFY_SYSTEM responses in libpqwalreceiver
libpqwalreceiver parses the WAL flush location returned by
IDENTIFY_SYSTEM using sscanf("%X/%X") into uint32 values. This
accepts overlong components and trailing characters, potentially
producing a different LSN from the one supplied by the upstream server.
Use pg_parse_lsn() instead, requiring one to eight hexadecimal digits
per component and no trailing characters, as for pg_lsn input. Reject
malformed locations with the existing protocol violation error.
Suggested-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Jan Nidzwetzki <jan@planetscale.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/tencent_C6ED19DF1759CDD37E786F7EE0B5207D0009@qq.com
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "common/connect.h"
|
||||
#include "common/pg_parse_lsn.h"
|
||||
#include "funcapi.h"
|
||||
#include "libpq-fe.h"
|
||||
#include "libpq/libpq-be-fe-helpers.h"
|
||||
@@ -458,15 +459,11 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli,
|
||||
/* Column 2 is the server's current WAL flush position */
|
||||
if (server_lsn)
|
||||
{
|
||||
uint32 hi,
|
||||
lo;
|
||||
|
||||
if (sscanf(PQgetvalue(res, 0, 2), "%X/%X", &hi, &lo) != 2)
|
||||
if (!pg_parse_lsn(PQgetvalue(res, 0, 2), server_lsn))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("could not parse WAL location \"%s\"",
|
||||
PQgetvalue(res, 0, 2))));
|
||||
*server_lsn = ((uint64) hi) << 32 | lo;
|
||||
}
|
||||
|
||||
PQclear(res);
|
||||
|
||||
Reference in New Issue
Block a user