From: Ben Pfaff Date: Thu, 16 Apr 2015 15:52:29 +0000 (-0700) Subject: ovs-lldp: Avoid free() of static data in aa_print_element_status_port(). X-Git-Tag: v2.4.0~319 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=f0b3bf9806356bda0db36c49e3356a3a1e3f5e59;p=cascardo%2Fovs.git ovs-lldp: Avoid free() of static data in aa_print_element_status_port(). In some cases 'id' could point to the static string "", which was then passed to free() even though it must not be. This commit fixes the problem. Found by LLVM scan-build. Reported-by: Kevin Lo Signed-off-by: Ben Pfaff Acked-by: Russell Bryant Acked-by: Dennis Flynn --- diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index 3edaf429a..9ee639e57 100644 --- a/lib/ovs-lldp.c +++ b/lib/ovs-lldp.c @@ -202,8 +202,10 @@ aa_print_element_status_port(struct ds *ds, struct lldpd_hardware *hw) if (memcmp(&port->p_element.system_id, &system_id_null, sizeof port->p_element.system_id)) { - static char *none_str = ""; - char *id = none_str, *descr = none_str, *system = none_str; + const char *none_str = ""; + const char *descr = NULL; + char *id = NULL; + char *system; if (port->p_chassis) { if (port->p_chassis->c_id_len > 0) { @@ -211,16 +213,16 @@ aa_print_element_status_port(struct ds *ds, struct lldpd_hardware *hw) port->p_chassis->c_id_len, &id); } - descr = port->p_chassis->c_descr - ? port->p_chassis->c_descr : none_str; + descr = port->p_chassis->c_descr; } chassisid_to_string((uint8_t *) &port->p_element.system_id, sizeof port->p_element.system_id, &system); - ds_put_format(ds, "\tAuto Attach Primary Server Id: %s\n", id); + ds_put_format(ds, "\tAuto Attach Primary Server Id: %s\n", + id ? id : none_str); ds_put_format(ds, "\tAuto Attach Primary Server Descr: %s\n", - descr); + descr ? descr : none_str); ds_put_format(ds, "\tAuto Attach Primary Server System Id: %s\n", system);