]> git.ozlabs.org Git - ppp.git/commitdiff
plugins/pppoatm: Restructure code to avoid possibility of integer overflow
authorPaul Mackerras <paulus@ozlabs.org>
Tue, 20 Aug 2024 10:27:31 +0000 (20:27 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Tue, 20 Aug 2024 10:27:31 +0000 (20:27 +1000)
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 <paulus@ozlabs.org>
pppd/plugins/pppoatm/text2qos.c

index 060407a026075e0746828dbcfe9389617b623182..2da1e50157a31ea9085bbeab31b87b62fc9e855d 100644 (file)
@@ -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;