Re: BUG #18745: /src/bin/pg_waldump/compat.c

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: dan-eli(at)mail(dot)ru, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18745: /src/bin/pg_waldump/compat.c
Date: 2024-12-11 21:18:05
Message-ID: EAB008E3-6B87-413F-BA39-22A6ED5DF0F6@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> On 9 Dec 2024, at 14:07, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 18745
> Logged by: Daniel Elishakov
> Email address: dan-eli(at)mail(dot)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.

diff --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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Artur Zakirov 2024-12-11 21:41:16 Re: pg_dump crash on identity sequence with not loaded attributes
Previous Message Tom Lane 2024-12-11 21:12:46 Re: BUG #18711: Attempting a connection with a database name longer than 63 characters now fails