pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18745: /src/bin/pg_waldump/compat.c
2+ messages / 2 participants
[nested] [flat]

* BUG #18745: /src/bin/pg_waldump/compat.c
@ 2024-12-09 13:07 PG Bug reporting form <noreply@postgresql.org>
  2024-12-11 21:18 ` Re: BUG #18745: /src/bin/pg_waldump/compat.c Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2024-12-09 13:07 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dan-eli@mail.ru

The following bug has been logged on the website:

Bug reference:      18745
Logged by:          Daniel Elishakov
Email address:      dan-eli@mail.ru
PostgreSQL version: 16.4
Operating system:   ubuntu 20.04
Description:        

Pointer 'ltime', returned from function 'localtime' at compat.c:55, may be
NULL and is dereferenced at compat.c:57 by calling function 'strftime'.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #18745: /src/bin/pg_waldump/compat.c
  2024-12-09 13:07 BUG #18745: /src/bin/pg_waldump/compat.c PG Bug reporting form <noreply@postgresql.org>
@ 2024-12-11 21:18 ` Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 0 replies; 2+ messages in thread

From: Daniel Gustafsson @ 2024-12-11 21:18 UTC (permalink / raw)
  To: dan-eli@mail.ru; pgsql-bugs@lists.postgresql.org

> On 9 Dec 2024, at 14:07, PG Bug reporting form <noreply@postgresql.org> wrote:
> 
> The following bug has been logged on the website:
> 
> Bug reference:      18745
> Logged by:          Daniel Elishakov
> Email address:      dan-eli@mail.ru
> PostgreSQL version: 16.4
> Operating system:   ubuntu 20.04
> Description:        
> 
> Pointer 'ltime', returned from function 'localtime' at compat.c:55, may be
> NULL and is dereferenced at compat.c:57 by calling function 'strftime'.

That's a fair point, ISTM we should mimic what the backend timestamptz_to_str
does with something like the following.  We could inspect errno and come up
with other errors as well but keeping the copies reasonably in sync for rare
errors seems worthwhile.

inline patch 1: src/bin/pg_waldump/compat.c (+6/-0 lines) download inline-1.patchdiff --git a/src/bin/pg_waldump/compat.c b/src/bin/pg_waldump/compat.c index 1541eac611..9e1a45af81 100644 --- a/src/bin/pg_waldump/compat.c +++ b/src/bin/pg_waldump/compat.c @@ -54,6 +54,12 @@ timestamptz_to_str(TimestampTz t) time_t result = (time_t) timestamptz_to_time_t(t); struct tm *ltime = localtime(&result); + if (!ltime) + { + strlcpy(buf, "(timestamp out of range)", sizeof(buf)); + return buf; + } + strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime); strftime(zone, sizeof(zone), "%Z", ltime);
-- Daniel Gustafsson ^ permalink raw reply [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-12-11 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-12-09 13:07 BUG #18745: /src/bin/pg_waldump/compat.c PG Bug reporting form <noreply@postgresql.org>
2024-12-11 21:18 ` Daniel Gustafsson <daniel@yesql.se>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox