[ovs-dev] [PATCH v2] dpif-netlink: fix null pointer

Matteo Croce mcroce at redhat.com
Mon Oct 8 15:18:04 UTC 2018


In dpif_netlink_port_add__(), socksp could be NULL, because
vport_socksp_to_pids() would allocate a new array and return a single
zero element.
Following vport_socksp_to_pids() removal, a NULL pointer can happen when
dpif_netlink_port_add__() is called and dpif->handlers is 0.

Restore the old behaviour of using a zero pid when dpif->handlers is 0.

Fixes: 69c51582f ("dpif-netlink: don't allocate per thread netlink sockets")
Reported-by: Flavio Leitner <fbl at redhat.com>
Reported-by: Guru Shetty <guru at ovn.org>
Tested-by: Guru Shetty <guru at ovn.org>
Signed-off-by: Matteo Croce <mcroce at redhat.com>
---
v2: fix checkpatch.py error about coding style

 lib/dpif-netlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 21315033c..ac3d2edeb 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -712,7 +712,7 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, const char *name,
     struct dpif_netlink_vport request, reply;
     struct ofpbuf *buf;
     struct nl_sock *socksp = NULL;
-    uint32_t upcall_pids;
+    uint32_t upcall_pids = 0;
     int error = 0;
 
     if (dpif->handlers) {
@@ -728,7 +728,9 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, const char *name,
     request.name = name;
 
     request.port_no = *port_nop;
-    upcall_pids = nl_sock_pid(socksp);
+    if (socksp) {
+        upcall_pids = nl_sock_pid(socksp);
+    }
     request.n_upcall_pids = 1;
     request.upcall_pids = &upcall_pids;
 
-- 
2.17.1



More information about the dev mailing list