vmbus: coverity bug fixes
cover vmbus: coverity bug fixes
Recent Covertity scan reported some issues in code that is unlikely to be used, but fix it anyway.
Stephen Hemminger (3):
vmbus: close directory in error path
vmbus: make sure path is null terminated
vmbus: handle eof on irq read
drivers/bus/vmbus/linux/vmbus_uio.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/3 vmbus: close directory in error path
Fix bug reported by Coverity where directory being scanned was not closed in error path (leaking file descriptor).
Coverity issue: 302848
--- drivers/bus/vmbus/linux/vmbus_uio.c | 1 + 1 file changed, 1 insertion(+)
drivers/bus/vmbus/linux/vmbus_uio.c +1 -0
@@ -357,6 +357,7 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary,if (err) {VMBUS_LOG (NOTICE ,"invalid subchannel id %lu" , subid); +closedir (chan_dir);return err; }
Signature · 1 line
2.18.0
PATCH 2/3 vmbus: make sure path is null terminated
In reply to Stephen HemmingerUse strlcpy rather than strncpy to avoid any issues about null termination.
Coverity issue 302859
--- drivers/bus/vmbus/linux/vmbus_uio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/bus/vmbus/linux/vmbus_uio.c +2 -1
@@ -18,6 +18,7 @@#include <rte_common.h> #include <rte_malloc.h> #include <rte_bus_vmbus.h> +#include <rte_string_fns.h> #include "private.h"
@@ -89,7 +90,7 @@ vmbus_uio_alloc_resource(struct rte_vmbus_device *dev, goto error; } -strncpy ((*uio_res)->path, devname,PATH_MAX ); +strlcpy ((*uio_res)->path, devname,PATH_MAX );rte_uuid_copy ((*uio_res)->id, dev->device_id);return 0 ;
Signature · 1 line
2.18.0
PATCH 3/3 vmbus: handle eof on irq read
In reply to Stephen HemmingerThis function is not used by netvsc driver yet. Still the code should handle case where device driver returns zero (due to rescind).
Coverity issue: 302871
--- drivers/bus/vmbus/linux/vmbus_uio.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/bus/vmbus/linux/vmbus_uio.c +11 -5
@@ -39,11 +39,17 @@ void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff)int vmbus_uio_irq_read (struct rte_vmbus_device *dev) {int32_t count; - -if (read (dev->intr_handle.fd, &count,sizeof (count)) <0 ) { -VMBUS_LOG (ERR ,"cannot read to %d:%s" , - dev->intr_handle.fd,strerror (errno)); - count = -errno; +int cc; + + cc =read (dev->intr_handle.fd, &count,sizeof (count)); +if (cc < (int )sizeof (count)) { +if (cc <0 ) { +VMBUS_LOG (ERR ,"IRQ read failed %s" , +strerror (errno)); +return -errno; + } +VMBUS_LOG (ERR ,"can't read IRQ count" ); +return -EINVAL ; }return count;
Signature · 1 line
2.18.0
Thomas Monjalon
Applied06/08/2018 20:11, Stephen Hemminger:
Quoted 7 lines
Recent Covertity scan reported some issues in code that is unlikely to be used, but fix it anyway.
Stephen Hemminger (3):
vmbus: close directory in error path
vmbus: make sure path is null terminated
vmbus: handle eof on irq read
Applied, thanks