Fix libvirtd free() segfault when migrating guest with deleted open vswitch port
Fix libvirtd free() segfault when migrating guest with deleted open vswitch port

libvirtd crashes on free()ing portData for an open vswitch port if that port
was deleted.  To reproduce:

ovs-vsctl del-port vnet0
virsh migrate --live kvm1 qemu+ssh://dstHost/system

Error message:
libvirtd: *** Error in `/usr/sbin/libvirtd': free(): invalid pointer: 0x000003ff90001e20 ***

The problem is that virCommandRun can return an empty string in the event that
the port being queried does not exist. When this happens then we are
unconditionally overwriting a newline character at position strlen()-1. When
strlen is 0, we overwrite memory that does not belong to the string.

The fix: Only overwrite the newline if the string is not empty.

Reviewed-by: Bjoern Walk <40545c009452f40d2ae0bbfbd987b332d274d328@linux.vnet.ibm.com>
Signed-off-by: Jason J. Herne <937084fec1b14b928d3b598c69ed20c9b59ffea8@linux.vnet.ibm.com>

VenkatDatta/libvirt,olafhering/libvirt,zippy2/libvirt,datto/libvirt,fabianfreyer/libvirt,rlaager/libvirt,rlaager/libvirt,fabianfreyer/libvirt,jardasgit/libvirt,fabianfreyer/libvirt,nertpinx/libvirt,fabianfreyer/libvirt,rlaager/libvirt,libvirt/libvirt,libvirt/libvirt,andreabolognani/libvirt,taget/libvirt,zippy2/libvirt,jardasgit/libvirt,nertpinx/libvirt,crobinso/libvirt,jfehlig/libvirt,jfehlig/libvirt,crobinso/libvirt,jardasgit/libvirt,datto/libvirt,olafhering/libvirt,nertpinx/libvirt,eskultety/libvirt,nertpinx/libvirt,taget/libvirt,andreabolognani/libvirt,datto/libvirt,datto/libvirt,eskultety/libvirt,VenkatDatta/libvirt,eskultety/libvirt,libvirt/libvirt,libvirt/libvirt,zippy2/libvirt,olafhering/libvirt,andreabolognani/libvirt,VenkatDatta/libvirt,VenkatDatta/libvirt,zippy2/libvirt,jardasgit/libvirt,crobinso/libvirt,taget/libvirt,nertpinx/libvirt,taget/libvirt,jardasgit/libvirt,rlaager/libvirt,fabianfreyer/libvirt,eskultety/libvirt,olafhering/libvirt,VenkatDatta/libvirt,taget/libvirt,rlaager/libvirt,eskultety/libvirt,jfehlig/libvirt,datto/libvirt,andreabolognani/libvirt,andreabolognani/libvirt,crobinso/libvirt,jfehlig/libvirt