Prevent integer overflow while reading netlink message 34/223934/1 accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.115147 accepted/tizen/6.0/unified/hotfix/20201103.002918 accepted/tizen/unified/20200217.213714 submit/tizen/20200212.014429 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192504 submit/tizen_6.0_hotfix/20201103.114804 tizen_6.0.m2_release
authorSangwan Kwon <sangwan.kwon@samsung.com>
Wed, 5 Feb 2020 06:12:56 +0000 (15:12 +0900)
committerSangwan Kwon <sangwan.kwon@samsung.com>
Wed, 5 Feb 2020 06:12:56 +0000 (15:12 +0900)
Change-Id: Icc8430bb6090b71620650b9886478ba645a67b64
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/netlink/netlink.cpp

index ea67f5f..7183101 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/netlink.h>
 
 #include <cstring>
+#include <limits>
 
 #include <klay/error.h>
 #include <klay/exception.h>
@@ -119,6 +120,10 @@ Netlink::Message Netlink::recv(int options)
 
        struct sockaddr_nl nladdr;
        socklen_t nladdrlen = sizeof(nladdr);
+
+       if (nlh.nlmsg_len > (std::numeric_limits<decltype(nlh.nlmsg_len)>::max() - NLMSG_HDRLEN))
+               throw klay::Exception("Netlink message is too large.");
+
        char buf[nlh.nlmsg_len + NLMSG_HDRLEN];
        do {
                ret = ::recvfrom(fd, buf, sizeof(buf), options,