netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH 1/2] meta: don't assume time_t is 64 bit in date_type_print()
@ 2023-08-22  8:13 Thomas Haller
  2023-08-22  8:13 ` [nft PATCH 2/2] meta: use reentrant localtime_r()/gmtime_r() functions Thomas Haller
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Thomas Haller @ 2023-08-22  8:13 UTC (permalink / raw)
  To: NetFilter; +Cc: Thomas Haller

time_t on 32bit arch is not uint64_t. Even if it always were, it would
be ugly to make such an assumption (without a static assert). Copy the
value to a time_t variable first.

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 src/meta.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/meta.c b/src/meta.c
index 822c2fd12b6f..0d4ae0261ff2 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -385,20 +385,23 @@ const struct datatype ifname_type = {
 
 static void date_type_print(const struct expr *expr, struct output_ctx *octx)
 {
-	uint64_t tstamp = mpz_get_uint64(expr->value);
+	uint64_t tstamp64 = mpz_get_uint64(expr->value);
+	time_t tstamp;
 	struct tm *tm, *cur_tm;
 	char timestr[21];
 
 	/* Convert from nanoseconds to seconds */
-	tstamp /= 1000000000L;
+	tstamp64 /= 1000000000L;
 
 	/* Obtain current tm, to add tm_gmtoff to the timestamp */
-	cur_tm = localtime((time_t *) &tstamp);
+	tstamp = tstamp64;
+	cur_tm = localtime(&tstamp);
 
 	if (cur_tm)
-		tstamp += cur_tm->tm_gmtoff;
+		tstamp64 += cur_tm->tm_gmtoff;
 
-	if ((tm = gmtime((time_t *) &tstamp)) != NULL &&
+	tstamp = tstamp64;
+	if ((tm = gmtime(&tstamp)) != NULL &&
 	     strftime(timestr, sizeof(timestr) - 1, "%Y-%m-%d %T", tm))
 		nft_print(octx, "\"%s\"", timestr);
 	else
-- 
2.41.0


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

end of thread, other threads:[~2023-08-22 16:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22  8:13 [nft PATCH 1/2] meta: don't assume time_t is 64 bit in date_type_print() Thomas Haller
2023-08-22  8:13 ` [nft PATCH 2/2] meta: use reentrant localtime_r()/gmtime_r() functions Thomas Haller
2023-08-22  8:54   ` Pablo Neira Ayuso
2023-08-22 11:39     ` Thomas Haller
2023-08-22 15:15       ` Thomas Haller
2023-08-22 16:06         ` Pablo Neira Ayuso
2023-08-22 16:04       ` Pablo Neira Ayuso
2023-08-22  8:54 ` [nft PATCH 1/2] meta: don't assume time_t is 64 bit in date_type_print() Pablo Neira Ayuso
2023-08-22  9:06 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).