Commit f1be740a authored by Tom Lane's avatar Tom Lane

Fix portability and safety issues in pqTraceFormatTimestamp.

Remove confusion between time_t and pg_time_t; neither
gettimeofday() nor localtime() deal in the latter.
libpq indeed has no business using <pgtime.h> at all.

Use snprintf not sprintf, to ensure we can't overrun the
supplied buffer.  (Unlikely, but let's be safe.)

Per buildfarm.
parent 8998e3ca
......@@ -26,7 +26,6 @@
#include "libpq-fe.h"
#include "libpq-int.h"
#include "pgtime.h"
#include "port/pg_bswap.h"
/* Enable tracing */
......@@ -81,16 +80,14 @@ static void
pqTraceFormatTimestamp(char *timestr, size_t ts_len)
{
struct timeval tval;
pg_time_t stamp_time;
gettimeofday(&tval, NULL);
stamp_time = (pg_time_t) tval.tv_sec;
strftime(timestr, ts_len,
"%Y-%m-%d %H:%M:%S",
localtime(&stamp_time));
localtime(&tval.tv_sec));
/* append microseconds */
sprintf(timestr + strlen(timestr), ".%06d", (int) (tval.tv_usec));
snprintf(timestr + strlen(timestr), ts_len - strlen(timestr),
".%06u", (unsigned int) (tval.tv_usec));
}
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment