mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "libpq-int.h"
|
#include "libpq-int.h"
|
||||||
#include "pgtime.h"
|
|
||||||
#include "port/pg_bswap.h"
|
#include "port/pg_bswap.h"
|
||||||
|
|
||||||
/* Enable tracing */
|
/* Enable tracing */
|
||||||
@ -81,16 +80,14 @@ static void
|
|||||||
pqTraceFormatTimestamp(char *timestr, size_t ts_len)
|
pqTraceFormatTimestamp(char *timestr, size_t ts_len)
|
||||||
{
|
{
|
||||||
struct timeval tval;
|
struct timeval tval;
|
||||||
pg_time_t stamp_time;
|
|
||||||
|
|
||||||
gettimeofday(&tval, NULL);
|
gettimeofday(&tval, NULL);
|
||||||
stamp_time = (pg_time_t) tval.tv_sec;
|
|
||||||
|
|
||||||
strftime(timestr, ts_len,
|
strftime(timestr, ts_len,
|
||||||
"%Y-%m-%d %H:%M:%S",
|
"%Y-%m-%d %H:%M:%S",
|
||||||
localtime(&stamp_time));
|
localtime(&tval.tv_sec));
|
||||||
/* append microseconds */
|
/* 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user