From: Bert van Hall Date: Tue, 30 Aug 2016 13:39:48 +0000 (+0200) Subject: lib/atoms/port: fix segfaults with minimal information X-Git-Tag: 0.9.5~13^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F198%2Fhead;p=thirdparty%2Flldpd.git lib/atoms/port: fix segfaults with minimal information When no packet has yet been received, querying LLDP information leads to segfaults. Fix those by adding a couple pointer checks. Signed-off-by: Bert van Hall --- diff --git a/src/lib/atoms/port.c b/src/lib/atoms/port.c index dda4d853..b4ea3464 100644 --- a/src/lib/atoms/port.c +++ b/src/lib/atoms/port.c @@ -156,10 +156,12 @@ _lldpctl_atom_new_port(lldpctl_atom_t *atom, va_list ap) if (port->parent) lldpctl_atom_inc_ref((lldpctl_atom_t*)port->parent); - /* Internal atom. We are the parent, but our reference count is not - * incremented. */ - port->chassis = _lldpctl_new_atom(atom->conn, atom_chassis, - port->port->p_chassis, port, 1); + if (port->port) { + /* Internal atom. We are the parent, but our reference count is + * not incremented. */ + port->chassis = _lldpctl_new_atom(atom->conn, atom_chassis, + port->port->p_chassis, port, 1); + } return 1; } @@ -197,7 +199,7 @@ _lldpctl_atom_free_port(lldpctl_atom_t *atom) TAILQ_INIT(&chassis_list); if (port->parent) lldpctl_atom_dec_ref((lldpctl_atom_t*)port->parent); - else if (!hardware) { + else if (!hardware && port->port) { /* No parent, no hardware, we assume a single neighbor: one * port, one chassis. */ if (port->port->p_chassis) { @@ -424,6 +426,9 @@ _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) default: break; } + if (!port) + return NULL; + /* Local and remote port */ switch (key) { case lldpctl_k_port_protocol: @@ -575,6 +580,8 @@ _lldpctl_atom_get_int_port(lldpctl_atom_t *atom, lldpctl_key_t key) default: break; } } + if (!port) + return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); /* Local and remote port */ switch (key) {