git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8998e3c)
Fix portability and safety issues in pqTraceFormatTimestamp.
2021年3月31日 21:00:30 +0000 (17:00 -0400)
2021年3月31日 21:00:30 +0000 (17:00 -0400)
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.


diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c
index 0bfae12a45025c1b48911a7a1e693e810a093bbb..5faeee745190575c8542414a68080d8785022738 100644 (file)
--- a/src/interfaces/libpq/fe-trace.c
+++ b/src/interfaces/libpq/fe-trace.c
@@ -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));
}
/*
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /