From 3e3db94ddce490bc1115f4c62b44f1803df457fc Mon Sep 17 00:00:00 2001 From: Patrick Grimm Date: Fri, 3 Jan 2025 15:56:29 +0100 Subject: [PATCH] owipcalc: fix integer overflow in func howmany Maintainer: Nick Hainke (@PolynomialDivision) This only works with numbers smaller than 2 to the power of 64, but the maximum is 2 to the power of 128. Replace bit shift with pow() form math.h Signed-off-by: Patrick Grimm --- net/owipcalc/Makefile | 2 +- net/owipcalc/src/owipcalc.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/net/owipcalc/Makefile b/net/owipcalc/Makefile index 282bcc14acbe4..4674f7f0dadc1 100644 --- a/net/owipcalc/Makefile +++ b/net/owipcalc/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=owipcalc -PKG_RELEASE:=7 +PKG_RELEASE:=8 PKG_MAINTAINER:=Nick Hainke PKG_LICENSE:=Apache-2.0 diff --git a/net/owipcalc/src/owipcalc.c b/net/owipcalc/src/owipcalc.c index e69654715ba2d..19faff0edee86 100644 --- a/net/owipcalc/src/owipcalc.c +++ b/net/owipcalc/src/owipcalc.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -616,13 +617,15 @@ struct cidr * cidr_parse(const char *op, const char *s, int af_hint) bool cidr_howmany(struct cidr *a, struct cidr *b) { + int prefix_diff; if (printed) qprintf(" "); - if (b->prefix < a->prefix) + prefix_diff = (b->prefix - a->prefix); + if (prefix_diff < 1) qprintf("0"); else - qprintf("%u", 1 << (b->prefix - a->prefix)); + qprintf("%.0LF", powl(2, prefix_diff)); return true; }