diff options
author | Thomas Haller <thaller@redhat.com> | 2023-08-22 10:13:09 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-08-22 10:56:46 +0200 |
commit | b8c54499cc4bac3fd86f32eefae0ce67e83fb5b8 (patch) | |
tree | 3a7511282f69d0481721d20a3ebc1881832fe65d /src | |
parent | 97c28c926096950f1646c99b85a31de309429a0c (diff) |
meta: don't assume time_t is 64 bit in date_type_print()
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/meta.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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 |