summaryrefslogtreecommitdiffstats
path: root/src/netlink_linearize.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2023-12-14 15:39:27 +0100
committerFlorian Westphal <fw@strlen.de>2023-12-14 17:53:43 +0100
commit0404ff08b3c18052e6689d75fa85275d3cef7e8e (patch)
treef790890dd3b7017cf86c9937f8bc4705bb516e7d /src/netlink_linearize.c
parent21657008dd4b4094eac017a175f2a3056af36b17 (diff)
netlink: don't crash if prefix for < byte is requested
If prefix is used with a datatype that has less than 8 bits an assertion is triggered: src/netlink.c:243: netlink_gen_raw_data: Assertion `len > 0' failed. This is esoteric, the alternative would be to restrict prefixes to ipv4/ipv6 addresses. Simpler fix is to use round_up instead of divide. Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/netlink_linearize.c')
-rw-r--r--src/netlink_linearize.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 61828eb9..d8b41a08 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -460,7 +460,8 @@ static struct expr *netlink_gen_prefix(struct netlink_linearize_ctx *ctx,
mpz_init(mask);
mpz_prefixmask(mask, expr->right->len, expr->right->prefix_len);
netlink_gen_raw_data(mask, expr->right->byteorder,
- expr->right->len / BITS_PER_BYTE, &nld);
+ div_round_up(expr->right->len, BITS_PER_BYTE),
+ &nld);
mpz_clear(mask);
zero.len = nld.len;