]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
common: Avoid integer overflow in nftnl_batch_is_supported()
authorPhil Sutter <phil@nwl.cc>
Thu, 11 Aug 2016 23:33:37 +0000 (01:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 11 Aug 2016 23:45:40 +0000 (01:45 +0200)
time() may return -1 which is then assigned to an unsigned integer type
and used as sequence number. The following code increments that number
multiple times, so it may overflow and get libmnl confused. To avoid
this, fall back to a starting sequence number of zero in case the call
to time() failed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/common.c

index bf4176ceb76ebb08c82f7c794a439408cd5de20b..2189cc8a3e882a47aa27ece19d6d0de0213adc58 100644 (file)
@@ -192,6 +192,9 @@ int nftnl_batch_is_supported(void)
        uint32_t seq = time(NULL), req_seq;
        int ret;
 
+       if (seq == (uint32_t)-1)
+               seq = 0;
+
        nl = mnl_socket_open(NETLINK_NETFILTER);
        if (nl == NULL)
                return -1;