From: Vincent Bernat Date: Sun, 4 Oct 2015 00:24:29 +0000 (+0200) Subject: protocols: don't use assert on paths that can be reached X-Git-Tag: 0.8.0~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9221b5c249f9e4843f77c7f888d5705348d179c0;p=thirdparty%2Flldpd.git protocols: don't use assert on paths that can be reached Malformed packets should not make lldpd crash. Ensure we can handle them by not using assert() in this part. --- diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 5fb3f204..be94f4f0 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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; diff --git a/src/daemon/protocols/cdp.c b/src/daemon/protocols/cdp.c index 8567679f..83745c8c 100644 --- a/src/daemon/protocols/cdp.c +++ b/src/daemon/protocols/cdp.c @@ -25,7 +25,6 @@ #include #include #include -#include 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); diff --git a/src/daemon/protocols/edp.c b/src/daemon/protocols/edp.c index 8eec547f..818dce92 100644 --- a/src/daemon/protocols/edp.c +++ b/src/daemon/protocols/edp.c @@ -25,7 +25,6 @@ #include #include #include -#include static int seq = 0; diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c index 5a5018bf..deddc3e7 100644 --- a/src/daemon/protocols/lldp.c +++ b/src/daemon/protocols/lldp.c @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -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); diff --git a/src/daemon/protocols/sonmp.c b/src/daemon/protocols/sonmp.c index 30930cb3..b55d73b7 100644 --- a/src/daemon/protocols/sonmp.c +++ b/src/daemon/protocols/sonmp.c @@ -24,7 +24,6 @@ #include #include #include -#include 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);