From 4a785cae3b0ea372c45357ce94a0610e0c205a4a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 20 Jul 2016 14:54:33 -0700 Subject: [PATCH] ovn-controller: Fix potential null pointer dereferences. Found by inspection. Signed-off-by: Ben Pfaff Acked-by: Andy Zhou --- ovn/controller/encaps.c | 11 ++++++++--- ovn/controller/patch.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ovn/controller/encaps.c b/ovn/controller/encaps.c index 03ec732e4..977cc3a1e 100644 --- a/ovn/controller/encaps.c +++ b/ovn/controller/encaps.c @@ -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); diff --git a/ovn/controller/patch.c b/ovn/controller/patch.c index 823389dbb..fa38f78a2 100644 --- a/ovn/controller/patch.c +++ b/ovn/controller/patch.c @@ -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; } } -- 2.20.1