]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: don't assume time_t is 64 bit in date_type_print()
authorThomas Haller <thaller@redhat.com>
Tue, 22 Aug 2023 08:13:09 +0000 (10:13 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 22 Aug 2023 08:56:46 +0000 (10:56 +0200)
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/meta.c

index 822c2fd12b6f60fd9455d8ac71ff54b8e9ee3320..aa538caf1621b102f9f6c727f0fca40c7ab2ac24 100644 (file)
@@ -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);
        struct tm *tm, *cur_tm;
        char timestr[21];
+       time_t tstamp;
 
        /* 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