From: Paul Mackerras Date: Tue, 20 Aug 2024 10:27:31 +0000 (+1000) Subject: plugins/pppoatm: Restructure code to avoid possibility of integer overflow X-Git-Tag: v2.5.1~20 X-Git-Url: https://git.ozlabs.org/?a=commitdiff_plain;h=17f324057084e73d1b21b58906dc3e42b958054f;p=ppp.git plugins/pppoatm: Restructure code to avoid possibility of integer overflow This avoids the theoretical possibility of integer overflow in adding a constant before dividing in order to get the effect of rounding up. Instead we divide and add 1 if the original value modulo the divisor is non-zero. Signed-off-by: Paul Mackerras --- diff --git a/pppd/plugins/pppoatm/text2qos.c b/pppd/plugins/pppoatm/text2qos.c index 060407a..2da1e50 100644 --- a/pppd/plugins/pppoatm/text2qos.c +++ b/pppd/plugins/pppoatm/text2qos.c @@ -66,8 +66,9 @@ int __t2q_get_rate(const char **text,int up) } else if (!strncmp(end,"cps",3)) end += 3; else if (!strncmp(end,"bps",3)) { - rate = (rate+(up ? 8*ATM_CELL_PAYLOAD-1 : 0))/8/ - ATM_CELL_PAYLOAD; + if (up && rate % (8 * ATM_CELL_PAYLOAD) == 0) + up = 0; + rate = rate / (8 * ATM_CELL_PAYLOAD) + !!up; end += 3; } else if (multiplier) return RATE_ERROR;