]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: Fix size of time_type
authorPhil Sutter <phil@nwl.cc>
Wed, 10 Mar 2021 13:38:37 +0000 (14:38 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 30 Nov 2021 13:57:46 +0000 (14:57 +0100)
Used by 'ct expiration', time_type is supposed to be 32bits. Passing a
64bits variable to constant_expr_alloc() causes the value to be always
zero on Big Endian.

Fixes: 0974fa84f162a ("datatype: seperate time parsing/printing from time_type")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/datatype.c

index a06c39960fa0cbc335f422300579d854bc2800d9..b2e667cef2c6208a982dd49d0e4e01caf32a88e2 100644 (file)
@@ -1068,6 +1068,7 @@ static struct error_record *time_type_parse(struct parse_ctx *ctx,
                                            struct expr **res)
 {
        struct error_record *erec;
+       uint32_t s32;
        uint64_t s;
 
        erec = time_parse(&sym->location, sym->identifier, &s);
@@ -1077,9 +1078,10 @@ static struct error_record *time_type_parse(struct parse_ctx *ctx,
        if (s > UINT32_MAX)
                return error(&sym->location, "value too large");
 
+       s32 = s;
        *res = constant_expr_alloc(&sym->location, &time_type,
                                   BYTEORDER_HOST_ENDIAN,
-                                  sizeof(uint32_t) * BITS_PER_BYTE, &s);
+                                  sizeof(uint32_t) * BITS_PER_BYTE, &s32);
        return NULL;
 }
 
@@ -1088,7 +1090,7 @@ const struct datatype time_type = {
        .name           = "time",
        .desc           = "relative time",
        .byteorder      = BYTEORDER_HOST_ENDIAN,
-       .size           = 8 * BITS_PER_BYTE,
+       .size           = 4 * BITS_PER_BYTE,
        .basetype       = &integer_type,
        .print          = time_type_print,
        .json           = time_type_json,