Skip to content

Commit d66e115

Browse files
author
Daniel Farina
committed
Convert bogus query error position into negative one.
Just in case this is uninitialized memory, do not leak it to the other end of the wire. Also, this can help with sanity checking. Signed-off-by: Daniel Farina <[email protected]>
1 parent 96a3b18 commit d66e115

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pg_logfebe.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,24 @@ fmtLogMsg(StringInfo dst, ErrorData *edata)
589589
/* errcontext */
590590
appendStringInfoPtr(dst, edata->context);
591591

592-
/* user query --- only reported if not disabled by the caller */
592+
/*
593+
* user query --- only reported if not disabled by the caller.
594+
*
595+
* Also include query position.
596+
*/
593597
if (isLogLevelOutput(edata->elevel, log_min_error_statement) &&
594598
debug_query_string != NULL && !edata->hide_stmt)
595599
{
600+
uint32_t nCursorPos = htobe32(edata->cursorpos);
601+
596602
appendStringInfoPtr(dst, debug_query_string);
603+
appendBinaryStringInfo(dst, (void *) &nCursorPos, sizeof nCursorPos);
597604
}
598605
else
599-
appendStringInfoPtr(dst, NULL);
600-
601-
/* Write cursor position, although it can be garbage sometimes. */
602606
{
603-
uint32_t nCursorPos = htobe32(edata->cursorpos);
607+
uint32_t nCursorPos = htobe32(-1);
604608

609+
appendStringInfoPtr(dst, NULL);
605610
appendBinaryStringInfo(dst, (void *) &nCursorPos, sizeof nCursorPos);
606611
}
607612

0 commit comments

Comments
 (0)