Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1be740

Browse files
committed
Fix portability and safety issues in pqTraceFormatTimestamp.
Remove confusion between time_t and pg_time_t; neithergettimeofday() 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 thesupplied buffer. (Unlikely, but let's be safe.)Per buildfarm.
1 parent8998e3c commitf1be740

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_tts_len)
8281
{
8382
structtimevaltval;
84-
pg_time_tstamp_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", (unsignedint) (tval.tv_usec));
9491
}
9592

9693
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp