ovs-lldp: Avoid free() of static data in aa_print_element_status_port().
authorBen Pfaff <blp@nicira.com>
Thu, 16 Apr 2015 15:52:29 +0000 (08:52 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 16 Apr 2015 17:39:34 +0000 (10:39 -0700)
In some cases 'id' could point to the static string "<None>", 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 <kevlo@FreeBSD.org>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
Acked-by: Dennis Flynn <drflynn@avaya.com>
lib/ovs-lldp.c

index 3edaf42..9ee639e 100644 (file)
@@ -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 = "<None>";
-            char *id = none_str, *descr = none_str, *system = none_str;
+            const char *none_str = "<None>";
+            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);