Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLU69-00F5qO-GY for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Dec 2024 21:18:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tLU66-002oaf-Ro for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Dec 2024 21:18:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLU66-002oaW-FB for pgsql-bugs@lists.postgresql.org; Wed, 11 Dec 2024 21:18:19 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLU64-002LP3-Vt for pgsql-bugs@lists.postgresql.org; Wed, 11 Dec 2024 21:18:19 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 6E9A81BA4B4 for ; Wed, 11 Dec 2024 22:18:16 +0100 (CET) Received: from s981.loopia.se (unknown [172.22.191.6]) by s807.loopia.se (Postfix) with ESMTP id 5EB811B9954; Wed, 11 Dec 2024 22:18:16 +0100 (CET) Received: from s474.loopia.se (unknown [172.22.191.5]) by s981.loopia.se (Postfix) with ESMTP id 5CD7A22B16DB; Wed, 11 Dec 2024 22:18:16 +0100 (CET) X-Virus-Scanned: amavisd-new at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s474.loopia.se (amavisd-new); dkim=pass (2048-bit key) header.d=yesql.se Received: from s899.loopia.se ([172.22.191.5]) by s474.loopia.se (s474.loopia.se [172.22.190.14]) (amavisd-new, port 10024) with LMTP id pJK4g-7FHvUD; Wed, 11 Dec 2024 22:18:15 +0100 (CET) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.193 Received: from smtpclient.apple (customer-89-255-232-193.stosn.net [89.255.232.193]) (Authenticated sender: daniel@yesql.se) by s899.loopia.se (Postfix) with ESMTPSA id 99CEC2C8BAA9; Wed, 11 Dec 2024 22:18:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1733951895; bh=X6kUUn6AJCoazDNhio8r9Nc0GSLVEHzCOxIDqPxglKk=; h=From:Subject:Date:References:To:In-Reply-To; b=BdUD5YCIQPw/sngmQ7pydxuJOOcYa3t1KJwFyPAxHaXTMvIB2zyEAVQMF/bpoT3pq CXdKUj/vPzmYtLtqqjRz96rN9lT0D5CoEsozoMXunWEznssFteEtByMeT58WVYiLxN KzNRqStUud0l8IBMNsHPlBNUNdDdGkKgY7O+xnFGsIRD8cbyg3mwXTo/m9oZnuHrtc bkAM2dcOAfwkGrphsOYhlELowuZ7wQ1k9SyUoZ121jy+cSdZiWGmp0IklLhKlj2fWp du5oAk3Om9cNJPiyt+lDSEoRkmQ7c3vW0J+Wv3DnKgMx0balCVWwCV8cwhosjX80eq CiC4ql4cydBuw== From: Daniel Gustafsson Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: BUG #18745: /src/bin/pg_waldump/compat.c Date: Wed, 11 Dec 2024 22:18:05 +0100 References: <18745-5afc39855ce0208e@postgresql.org> To: dan-eli@mail.ru, pgsql-bugs@lists.postgresql.org In-Reply-To: <18745-5afc39855ce0208e@postgresql.org> Message-Id: X-Mailer: Apple Mail (2.3776.700.51.11.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 9 Dec 2024, at 14:07, PG Bug reporting form = wrote: >=20 > The following bug has been logged on the website: >=20 > Bug reference: 18745 > Logged by: Daniel Elishakov > Email address: dan-eli@mail.ru > PostgreSQL version: 16.4 > Operating system: ubuntu 20.04 > Description: =20 >=20 > 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 =3D (time_t) timestamptz_to_time_t(t); struct tm *ltime =3D 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