[ovs-dev] [PATCH] ovs-lldp: Avoid free() of static data in aa_print_element_status_port().
Dennis Flynn
dflynn20 at gmail.com
Thu Apr 16 16:52:05 UTC 2015
Thanks for finding and fixing this.
Acked-by: Dennis Flynn <drflynn at avaya.com>
On Thu, Apr 16, 2015 at 11:52 AM, Ben Pfaff <blp at nicira.com> wrote:
> 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 at FreeBSD.org>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> lib/ovs-lldp.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c
> index 3edaf42..9ee639e 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 = "<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);
>
> --
> 2.1.3
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
More information about the dev
mailing list