Skip to content

Commit f1be740

Browse files
committed
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.
1 parent 8998e3c commit f1be740

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/interfaces/libpq/fe-trace.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include "libpq-fe.h"
2828
#include "libpq-int.h"
29-
#include "pgtime.h"
3029
#include "port/pg_bswap.h"
3130

3231
/* Enable tracing */
@@ -81,16 +80,14 @@ static void
8180
pqTraceFormatTimestamp(char *timestr, size_t ts_len)
8281
{
8382
struct timeval tval;
84-
pg_time_t stamp_time;
8583

8684
gettimeofday(&tval, NULL);
87-
stamp_time = (pg_time_t) tval.tv_sec;
88-
8985
strftime(timestr, ts_len,
9086
"%Y-%m-%d %H:%M:%S",
91-
localtime(&stamp_time));
87+
localtime(&tval.tv_sec));
9288
/* append microseconds */
93-
sprintf(timestr + strlen(timestr), ".%06d", (int) (tval.tv_usec));
89+
snprintf(timestr + strlen(timestr), ts_len - strlen(timestr),
90+
".%06u", (unsigned int) (tval.tv_usec));
9491
}
9592

9693
/*

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