Skip to content

Commit

Permalink
plugins/pppoatm: Restructure code to avoid possibility of integer ove…
Browse files Browse the repository at this point in the history
…rflow

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 <[email protected]>
  • Loading branch information
paulusmack committed Aug 20, 2024
1 parent 7eb932b commit 17f3240
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pppd/plugins/pppoatm/text2qos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 17f3240

Please sign in to comment.