lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <281e37b4ae33195fa475a2ceabf5c784785077b4.1432928262.git.daniel@iogearbox.net>
Date:	Fri, 29 May 2015 21:47:45 +0200
From:	Daniel Borkmann <daniel@...earbox.net>
To:	stephen@...workplumber.org
Cc:	jose.r.guzman.mosqueda@...el.com, edumazet@...gle.com,
	netdev@...r.kernel.org, Daniel Borkmann <daniel@...earbox.net>
Subject: [PATCH iproute2] 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: 8cecdc283743 ("tc: more user friendly rates")
Reported-by: Jose R. Guzman Mosqueda <jose.r.guzman.mosqueda@...el.com>
Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
---
 tc/tc_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tc/tc_util.c b/tc/tc_util.c
index dc2b70f..aa6de24 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -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);
 }
 
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ