]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib/atoms/port: fix segfaults with minimal information 198/head
authorBert van Hall <bert.vanhall@avionic-design.de>
Tue, 30 Aug 2016 13:39:48 +0000 (15:39 +0200)
committerBert van Hall <bert.vanhall@avionic-design.de>
Tue, 30 Aug 2016 13:57:47 +0000 (15:57 +0200)
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 <bert.vanhall@avionic-design.de>
src/lib/atoms/port.c

index dda4d8536a865ddb2a5348d0d4a0523f0e25a220..b4ea346459c2cd9396e97453d6038ceaf965d5e0 100644 (file)
@@ -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) {