ovn-controller: Fix potential null pointer dereferences.
authorBen Pfaff <blp@ovn.org>
Wed, 20 Jul 2016 21:54:33 +0000 (14:54 -0700)
committerBen Pfaff <blp@ovn.org>
Fri, 22 Jul 2016 18:19:47 +0000 (11:19 -0700)
Found by inspection.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
ovn/controller/encaps.c
ovn/controller/patch.c

index 03ec732..977cc3a 100644 (file)
@@ -103,6 +103,10 @@ port_hash_rec(const struct ovsrec_port *port)
 
     iface = port->interfaces[0];
     ip = smap_get(&iface->options, "remote_ip");
+    if (!ip) {
+        /* This should not happen for an OVN-created port. */
+        return 0;
+    }
 
     return port_hash(chassis_id, iface->type, ip);
 }
@@ -314,7 +318,8 @@ check_and_update_tunnel(const struct sbrec_chassis *chassis_rec)
         if (strcmp(encap->type, iface->type)) {
             ovsrec_interface_set_type(iface, encap->type);
         }
-        if (strcmp(encap->ip, smap_get(&iface->options, "remote_ip"))) {
+        const char *ip = smap_get(&iface->options, "remote_ip");
+        if (!ip || strcmp(encap->ip, ip)) {
             struct smap options = SMAP_INITIALIZER(&options);
             smap_add(&options, "remote_ip", encap->ip);
             smap_add(&options, "key", "flow");
@@ -322,8 +327,8 @@ check_and_update_tunnel(const struct sbrec_chassis *chassis_rec)
             smap_destroy(&options);
         }
 
-        if (strcmp(chassis_rec->name, smap_get(&port->external_ids,
-                                               "ovn-chassis-id"))) {
+        const char *chassis = smap_get(&port->external_ids, "ovn-chassis-id");
+        if (!chassis || strcmp(chassis_rec->name, chassis)) {
             const struct smap id = SMAP_CONST1(&id, "ovn-chassis-id",
                                                chassis_rec->name);
             ovsrec_port_set_external_ids(port, &id);
index 823389d..fa38f78 100644 (file)
@@ -349,7 +349,7 @@ add_logical_patch_ports(struct controller_ctx *ctx,
         if (!strcmp(binding->type, "gateway")) {
             const char *chassis = smap_get(&binding->options,
                                            "gateway-chassis");
-            if (!strcmp(local_chassis_id, chassis)) {
+            if (chassis && !strcmp(local_chassis_id, chassis)) {
                 local_port = true;
             }
         }