mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2026-02-01 16:38:22 +00:00
tc: util: fix print_rate for ludicrous speeds
The for loop should only probe up to G[i]bit rates, so that we
end up with T[i]bit as the last max units[] slot for snprintf(3),
and not possibly an invalid pointer in case rate is multiple of
kilo.
Fixes: 8cecdc2837 ("tc: more user friendly rates")
Reported-by: Jose R. Guzman Mosqueda <jose.r.guzman.mosqueda@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
518af1e0b1
commit
ad1fe0d8e9
@ -250,18 +250,19 @@ void print_rate(char *buf, int len, __u64 rate)
|
||||
extern int use_iec;
|
||||
unsigned long kilo = use_iec ? 1024 : 1000;
|
||||
const char *str = use_iec ? "i" : "";
|
||||
int i = 0;
|
||||
static char *units[5] = {"", "K", "M", "G", "T"};
|
||||
int i;
|
||||
|
||||
rate <<= 3; /* bytes/sec -> bits/sec */
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(units); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(units) - 1; i++) {
|
||||
if (rate < kilo)
|
||||
break;
|
||||
if (((rate % kilo) != 0) && rate < 1000*kilo)
|
||||
break;
|
||||
rate /= kilo;
|
||||
}
|
||||
|
||||
snprintf(buf, len, "%.0f%s%sbit", (double)rate, units[i], str);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user