[dpdk-dev] vhost: fix unchecked return value

Message ID 1506082660-46479-1-git-send-email-kubax.kozak@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Kuba Kozak Sept. 22, 2017, 12:17 p.m. UTC
  Add return value check for poll() call.

Coverity issue: 140740
Fixes: 59317cef249c ("vhost: allow many vhost-user ports")
Cc: jan.wickbom@ericsson.com
Cc: stable@dpdk.org

Signed-off-by: Kuba Kozak <kubax.kozak@intel.com>
---
 lib/librte_vhost/fd_man.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Michal Jastrzebski Oct. 2, 2017, 2:18 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Kuba Kozak
> Sent: Friday, September 22, 2017 2:18 PM
> To: yliu@fridaylinux.org; maxime.coquelin@redhat.com
> Cc: dev@dpdk.org; Kozak, KubaX <kubax.kozak@intel.com>;
> jan.wickbom@ericsson.com; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] vhost: fix unchecked return value
> 
> Add return value check for poll() call.
> 
> Coverity issue: 140740
> Fixes: 59317cef249c ("vhost: allow many vhost-user ports")
> Cc: jan.wickbom@ericsson.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Kuba Kozak <kubax.kozak@intel.com>
> ---
>  lib/librte_vhost/fd_man.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
> index 2ceacc9..4c6fed4 100644
> --- a/lib/librte_vhost/fd_man.c
> +++ b/lib/librte_vhost/fd_man.c
> @@ -222,6 +222,7 @@ fdset_event_dispatch(void *arg)
>  	int remove1, remove2;
>  	int need_shrink;
>  	struct fdset *pfdset = arg;
> +	int val;
> 
>  	if (pfdset == NULL)
>  		return NULL;
> @@ -239,7 +240,9 @@ fdset_event_dispatch(void *arg)
>  		numfds = pfdset->num;
>  		pthread_mutex_unlock(&pfdset->fd_mutex);
> 
> -		poll(pfdset->rwfds, numfds, 1000 /* millisecs */);
> +		val = poll(pfdset->rwfds, numfds, 1000 /* millisecs */);
> +		if (val < 0)
> +			continue;
> 
>  		need_shrink = 0;
>  		for (i = 0; i < numfds; i++) {
> --
> 2.7.4

Hi Yu / Maxime,
I would like to ask for a feedback regarding proposed fix.
If everything is ok with it, please send acked-by.

Best regards
Michal.
  
Yuanhan Liu Oct. 9, 2017, 3:10 a.m. UTC | #2
On Fri, Sep 22, 2017 at 02:17:40PM +0200, Kuba Kozak wrote:
> Add return value check for poll() call.
> 
> Coverity issue: 140740
> Fixes: 59317cef249c ("vhost: allow many vhost-user ports")
> Cc: jan.wickbom@ericsson.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Kuba Kozak <kubax.kozak@intel.com>

Applied to dpdk-next-virtio.

Thanks.

	--yliu
  

Patch

diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c
index 2ceacc9..4c6fed4 100644
--- a/lib/librte_vhost/fd_man.c
+++ b/lib/librte_vhost/fd_man.c
@@ -222,6 +222,7 @@  fdset_event_dispatch(void *arg)
 	int remove1, remove2;
 	int need_shrink;
 	struct fdset *pfdset = arg;
+	int val;
 
 	if (pfdset == NULL)
 		return NULL;
@@ -239,7 +240,9 @@  fdset_event_dispatch(void *arg)
 		numfds = pfdset->num;
 		pthread_mutex_unlock(&pfdset->fd_mutex);
 
-		poll(pfdset->rwfds, numfds, 1000 /* millisecs */);
+		val = poll(pfdset->rwfds, numfds, 1000 /* millisecs */);
+		if (val < 0)
+			continue;
 
 		need_shrink = 0;
 		for (i = 0; i < numfds; i++) {