From: Andreas Hofmeister Date: Sun, 28 Feb 2010 16:26:14 +0000 (+0100) Subject: Fix error handling in location data. X-Git-Tag: 0.5.0~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c26500bef4fc89f446ac5983366f9a97cf12ef0;p=thirdparty%2Flldpd.git Fix error handling in location data. Instead of just logging an invalid data length for location data, an error element is emited to the output. An unknown location fromat is now enclosed in an "unknown" tag to prevent that the "location" element ever contains character data. --- diff --git a/src/display.c b/src/display.c index 8e1be277..c7a1c5b1 100644 --- a/src/display.c +++ b/src/display.c @@ -562,9 +562,9 @@ display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port * case LLDPMED_LOCFORMAT_COORD: tag_attr(w, "type", "Type", "coordinates"); - if (port->p_med_location[i].data_len != 16) - LLOG_WARN("bad data length"); - else { + if (port->p_med_location[i].data_len != 16) { + tag_datatag(w, "error", "Error", "bad data length"); + } else { u_int64_t l; u_int8_t v; char * s; @@ -614,9 +614,9 @@ display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port * if ((port->p_med_location[i].data_len < 3) || (port->p_med_location[i].data_len - 1 != - *(u_int8_t*)port->p_med_location[i].data)) - LLOG_WARN("bad data length"); - else { + *(u_int8_t*)port->p_med_location[i].data)) { + tag_datatag(w, "error", "Error", "bad data length"); + } else { int l = 4, n, catype, calength; char country[3]; country[0] = ((char *)port->p_med_location[i].data)[2]; @@ -632,7 +632,7 @@ display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port * calength = *(u_int8_t*)(port-> p_med_location[i].data + l + 1); if (n < 2 + calength) { - LLOG_WARN("bad data length"); + tag_datatag(w, "error", "Error", "bad data length"); break; } @@ -664,7 +664,8 @@ display_med(struct writer *w, struct lldpd_chassis *chassis, struct lldpd_port * break; default: tag_attr(w, "type", "", "unknown"); - tag_data(w, dump(port->p_med_location[i].data, + tag_datatag(w, "unknown", "Data", + dump(port->p_med_location[i].data, port->p_med_location[i].data_len, 20, ' ')); } tag_end(w);