]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
protocols: don't use assert on paths that can be reached
authorVincent Bernat <vincent@bernat.im>
Sun, 4 Oct 2015 00:24:29 +0000 (02:24 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 4 Oct 2015 00:24:29 +0000 (02:24 +0200)
Malformed packets should not make lldpd crash. Ensure we can handle them
by not using assert() in this part.

src/daemon/lldpd.c
src/daemon/protocols/cdp.c
src/daemon/protocols/edp.c
src/daemon/protocols/lldp.c
src/daemon/protocols/sonmp.c

index 5fb3f2040820ff4dbf49685215e87f2854c08e94..be94f4f0ffa546fd500f7c2abe82cf536c9400b0 100644 (file)
@@ -252,7 +252,6 @@ lldpd_alloc_mgmt(int family, void *addrptr, size_t addrsize, u_int32_t iface)
                return NULL;
        }
        mgmt->m_family = family;
-       assert(addrsize <= LLDPD_MGMT_MAXADDRSIZE);
        memcpy(&mgmt->m_addr, addrptr, addrsize);
        mgmt->m_addrsize = addrsize;
        mgmt->m_iface = iface;
index 8567679fd0b8f17416810fd640311b0a407fd0e9..83745c8ca7e1b68cbb93ba870830f6a3f866c1c6 100644 (file)
@@ -25,7 +25,6 @@
 #include <unistd.h>
 #include <errno.h>
 #include <arpa/inet.h>
-#include <assert.h>
 
 static int
 cdp_send(struct lldpd *global,
@@ -438,8 +437,13 @@ cdp_decode(struct lldpd *cfg, char *frame, int s,
                                                mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, 
                                                                        sizeof(struct in_addr), 0);
                                                if (mgmt == NULL) {
-                                                       assert(errno == ENOMEM);
-                                                       log_warn("cdp", "unable to allocate memory for management address");
+                                                       if (errno == ENOMEM)
+                                                               log_warn("cdp",
+                                                                   "unable to allocate memory for management address");
+                                                       else
+                                                               log_warn("cdp",
+                                                                   "too large management address received on %s",
+                                                                   hardware->h_ifname);
                                                        goto malformed;
                                                }
                                                TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
index 8eec547f2fe285cdb979f9db40851c5bda6241b9..818dce92542a11d8796271ad1fe16e710715a2e3 100644 (file)
@@ -25,7 +25,6 @@
 #include <errno.h>
 #include <arpa/inet.h>
 #include <fnmatch.h>
-#include <assert.h>
 
 static int seq = 0;
 
index 5a5018bfffc9a6628423b8f42f144d08d6714b02..deddc3e757414224ab01f76b5024ba24e49fa5b2 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <unistd.h>
 #include <errno.h>
-#include <assert.h>
 #include <time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -161,7 +160,7 @@ static int _lldp_send(struct lldpd *global,
        /* Management addresses */
        TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) {
                proto = lldpd_af_to_lldp_proto(mgmt->m_family);
-               assert(proto != LLDP_MGMT_ADDR_NONE);
+               if (proto == LLDP_MGMT_ADDR_NONE) continue;
                if (!(
                          POKE_START_LLDP_TLV(LLDP_TLV_MGMT_ADDR) &&
                          /* Size of the address, including its type */
@@ -749,9 +748,12 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
                                iface = 0;
                        mgmt = lldpd_alloc_mgmt(af, addr_ptr, addr_length, iface);
                        if (mgmt == NULL) {
-                               assert(errno == ENOMEM);
-                               log_warn("lldp", "unable to allocate memory "
-                                   "for management address");
+                               if (errno == ENOMEM)
+                                       log_warn("lldp", "unable to allocate memory "
+                                           "for management address");
+                               else
+                                       log_warn("lldp", "too large management address "
+                                           "received on %s", hardware->h_ifname);
                                goto malformed;
                        }
                        TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);
index 30930cb340934dae8e3022f40d947b60ecae0747..b55d73b7a59b078eb759a44ce507a6f70a0c62ca 100644 (file)
@@ -24,7 +24,6 @@
 #include <unistd.h>
 #include <errno.h>
 #include <arpa/inet.h>
-#include <assert.h>
 
 static struct sonmp_chassis sonmp_chassis_types[] = {
        {1, "unknown (via SONMP)"},
@@ -358,8 +357,11 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s,
        }
        mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address, sizeof(struct in_addr), 0);
        if (mgmt == NULL) {
-               assert(errno == ENOMEM);
-               log_warn("sonmp", "unable to allocate memory for management address");
+               if (errno == ENOMEM)
+                       log_warn("sonmp", "unable to allocate memory for management address");
+               else
+                       log_warn("sonmp", "too large management address received on %s",
+                           hardware->h_ifname);
                goto malformed;
        }
        TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries);