From 64d84b4a3f8715c6b29f818667585d125dcd03d3 Mon Sep 17 00:00:00 2001 From: Anthonin Bonnefoy Date: Fri, 31 Jul 2026 09:57:22 +0200 Subject: Add mismatch length check on pqTraceOutputNoTypeByteMessage Currently, pqTraceOutputMessage checks that traced messages are correctly consumed. However, such a check doesn't exist for messages with no type. This commit adds a similar check in pqTraceOutputNoTypeByteMessage, checking that the consumed bytes matches the message length. --- src/interfaces/libpq/fe-trace.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c index 03845516917..e136c77e6b0 100644 --- a/src/interfaces/libpq/fe-trace.c +++ b/src/interfaces/libpq/fe-trace.c @@ -944,9 +944,24 @@ pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message) pqTraceOutputString(conn->Pfdebug, message, &logCursor, false); pqTraceOutputString(conn->Pfdebug, message, &logCursor, regress); } + + /* + * Startup messages end with a trailing terminator, advance our cursor + * to include it + */ + logCursor++; } fputc('\n', conn->Pfdebug); + + /* + * Verify the printing routine did it right. There's no one-byte message + * identifier here, so logCursor should match the length + */ + if (logCursor != length) + fprintf(conn->Pfdebug, + "mismatched message length: consumed %d, expected %d\n", + logCursor, length); } /* -- 2.55.0