libpq: Add suppress argument to pqTraceOutputNchar

In future commits we're going to trace authentication related messages.
Some of these messages contain challenge bytes as part of a
challenge-response flow.  Since these bytes are different for every
connection, we want to normalize them when the PQTRACE_REGRESS_MODE
trace flag is set.  This commit modifies pqTraceOutputNchar to take a
suppress argument, which makes it possible to do so.

Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com
This commit is contained in:
Alvaro Herrera 2024-08-08 20:35:12 -04:00
parent a90bdd7a44
commit 4eb179e5bf
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
1 changed files with 16 additions and 5 deletions

View File

@ -158,6 +158,8 @@ pqTraceOutputInt32(FILE *pfdebug, const char *data, int *cursor, bool suppress)
/*
* pqTraceOutputString: output a string message to the log
*
* If 'suppress' is true, print a literal "SSSS" instead of the actual string.
*/
static void
pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
@ -183,14 +185,23 @@ pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
/*
* pqTraceOutputNchar: output a string of exactly len bytes message to the log
*
* If 'suppress' is true, print a literal 'BBBB' instead of the actual bytes.
*/
static void
pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor)
pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
{
int i,
next; /* first char not yet printed */
const char *v = data + *cursor;
if (suppress)
{
fprintf(pfdebug, " 'BBBB'");
*cursor += len;
return;
}
fprintf(pfdebug, " \'");
for (next = i = 0; i < len; ++i)
@ -246,7 +257,7 @@ pqTraceOutput_Bind(FILE *f, const char *message, int *cursor)
nbytes = pqTraceOutputInt32(f, message, cursor, false);
if (nbytes == -1)
continue;
pqTraceOutputNchar(f, nbytes, message, cursor);
pqTraceOutputNchar(f, nbytes, message, cursor, false);
}
nparams = pqTraceOutputInt16(f, message, cursor);
@ -283,7 +294,7 @@ pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
len = pqTraceOutputInt32(f, message, cursor, false);
if (len == -1)
continue;
pqTraceOutputNchar(f, len, message, cursor);
pqTraceOutputNchar(f, len, message, cursor, false);
}
}
@ -363,7 +374,7 @@ pqTraceOutput_FunctionCall(FILE *f, const char *message, int *cursor, bool regre
nbytes = pqTraceOutputInt32(f, message, cursor, false);
if (nbytes == -1)
continue;
pqTraceOutputNchar(f, nbytes, message, cursor);
pqTraceOutputNchar(f, nbytes, message, cursor, false);
}
pqTraceOutputInt16(f, message, cursor);
@ -487,7 +498,7 @@ pqTraceOutput_FunctionCallResponse(FILE *f, const char *message, int *cursor)
fprintf(f, "FunctionCallResponse\t");
len = pqTraceOutputInt32(f, message, cursor, false);
if (len != -1)
pqTraceOutputNchar(f, len, message, cursor);
pqTraceOutputNchar(f, len, message, cursor, false);
}
static void