]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
statement: Fix get_rate() for zero byte_rate
authorPhil Sutter <phil@nwl.cc>
Tue, 24 Apr 2018 09:46:01 +0000 (11:46 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Apr 2018 10:06:22 +0000 (12:06 +0200)
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/statement.c

index f81e0123adda014fb55984b8d51cf885a61ee093..fccf71c10b1d4248ed4beb2ad4695b83a2c1d7f0 100644 (file)
@@ -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;