[ovs-dev] [PATCH] lib: Add initalize when xmalloc ofproto: Add initalize when recv from sdn controller

findtheonlyway at gmail.com findtheonlyway at gmail.com
Thu Jun 14 08:18:27 UTC 2018


From: findtheonlway <findtheonlyway at example.com>

When recv packet from onos, the ovs may report an error or
crash due to the buffer is uninitalized.

Signed-off-by: findtheonlway <findtheonlyway at gmail.com>
Signed-off-by: sunwenjie <sunwenjie at didichuxing.com>
---
 lib/util.c        | 1 +
 ofproto/ofproto.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/lib/util.c b/lib/util.c
index 7152b5539..e44f8f50a 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -122,6 +122,7 @@ xmalloc(size_t size)
     if (p == NULL) {
         out_of_memory();
     }
+    memset(p, 0, size ? size : 1);
     return p;
 }
 
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 829ccd866..18a9b49e0 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -3559,6 +3559,9 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh)
         return error;
     }
 
+    memset(&po, 0, sizeof(struct ofputil_packet_out));
+    memset(&opo, 0, sizeof(struct ofputil_packet_out));
+
     /* Decode message. */
     ofpbuf_use_stub(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
     error = ofputil_decode_packet_out(&po, oh, ofproto_get_tun_tab(p),
-- 
2.14.1



More information about the dev mailing list