Skip to content

Commit 4eb179e

Browse files
committed
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
1 parent a90bdd7 commit 4eb179e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/interfaces/libpq/fe-trace.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pqTraceOutputInt32(FILE *pfdebug, const char *data, int *cursor, bool suppress)
158158

159159
/*
160160
* pqTraceOutputString: output a string message to the log
161+
*
162+
* If 'suppress' is true, print a literal "SSSS" instead of the actual string.
161163
*/
162164
static void
163165
pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
@@ -183,14 +185,23 @@ pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
183185

184186
/*
185187
* pqTraceOutputNchar: output a string of exactly len bytes message to the log
188+
*
189+
* If 'suppress' is true, print a literal 'BBBB' instead of the actual bytes.
186190
*/
187191
static void
188-
pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor)
192+
pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
189193
{
190194
int i,
191195
next; /* first char not yet printed */
192196
const char *v = data + *cursor;
193197

198+
if (suppress)
199+
{
200+
fprintf(pfdebug, " 'BBBB'");
201+
*cursor += len;
202+
return;
203+
}
204+
194205
fprintf(pfdebug, " \'");
195206

196207
for (next = i = 0; i < len; ++i)
@@ -246,7 +257,7 @@ pqTraceOutput_Bind(FILE *f, const char *message, int *cursor)
246257
nbytes = pqTraceOutputInt32(f, message, cursor, false);
247258
if (nbytes == -1)
248259
continue;
249-
pqTraceOutputNchar(f, nbytes, message, cursor);
260+
pqTraceOutputNchar(f, nbytes, message, cursor, false);
250261
}
251262

252263
nparams = pqTraceOutputInt16(f, message, cursor);
@@ -283,7 +294,7 @@ pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
283294
len = pqTraceOutputInt32(f, message, cursor, false);
284295
if (len == -1)
285296
continue;
286-
pqTraceOutputNchar(f, len, message, cursor);
297+
pqTraceOutputNchar(f, len, message, cursor, false);
287298
}
288299
}
289300

@@ -363,7 +374,7 @@ pqTraceOutput_FunctionCall(FILE *f, const char *message, int *cursor, bool regre
363374
nbytes = pqTraceOutputInt32(f, message, cursor, false);
364375
if (nbytes == -1)
365376
continue;
366-
pqTraceOutputNchar(f, nbytes, message, cursor);
377+
pqTraceOutputNchar(f, nbytes, message, cursor, false);
367378
}
368379

369380
pqTraceOutputInt16(f, message, cursor);
@@ -487,7 +498,7 @@ pqTraceOutput_FunctionCallResponse(FILE *f, const char *message, int *cursor)
487498
fprintf(f, "FunctionCallResponse\t");
488499
len = pqTraceOutputInt32(f, message, cursor, false);
489500
if (len != -1)
490-
pqTraceOutputNchar(f, len, message, cursor);
501+
pqTraceOutputNchar(f, len, message, cursor, false);
491502
}
492503

493504
static void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy