diff mbox series

[nft] statement: Fix get_rate() for zero byte_rate

Message ID 20180424094601.29212-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series [nft] statement: Fix get_rate() for zero byte_rate | expand

Commit Message

Phil Sutter April 24, 2018, 9:46 a.m. UTC
The algorithm didn't detect whether given byte_rate was zero,
pointlessly iterating through data units. Make it exit early in this
case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/statement.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Pablo Neira Ayuso April 24, 2018, 10:05 a.m. UTC | #1
On Tue, Apr 24, 2018 at 11:46:01AM +0200, Phil Sutter wrote:
> The algorithm didn't detect whether given byte_rate was zero,
> pointlessly iterating through data units. Make it exit early in this
> case.

Also applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/src/statement.c b/src/statement.c
index f81e0123adda0..fccf71c10b1d4 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -313,6 +313,11 @@  const char *get_rate(uint64_t byte_rate, uint64_t *rate)
 {
 	int i;
 
+	if (!byte_rate) {
+		*rate = 0;
+		return data_unit[0];
+	}
+
 	for (i = 0; data_unit[i + 1] != NULL; i++) {
 		if (byte_rate % 1024)
 			break;