diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-08-08 20:35:12 -0400 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-08-08 20:35:12 -0400 |
commit | 4eb179e5bf7a5551ce3963d1563d6c9968c1a257 (patch) | |
tree | 7f1e40673ec6f07c2cc1046edb974ede4fe7133f /src | |
parent | a90bdd7a44d088a10b2faf5d7cdb85b8e4f0c662 (diff) | |
download | postgresql-4eb179e5bf7a5551ce3963d1563d6c9968c1a257.tar.gz postgresql-4eb179e5bf7a5551ce3963d1563d6c9968c1a257.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/libpq/fe-trace.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c index d7a61ec9cc1..c479ea19c44 100644 --- a/src/interfaces/libpq/fe-trace.c +++ b/src/interfaces/libpq/fe-trace.c @@ -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 |