[dpdk-dev] net/virtio: fix null pointer dereference

Message ID 1467718979-20904-1-git-send-email-jianfeng.tan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Commit Message

Jianfeng Tan July 5, 2016, 11:42 a.m. UTC
  There is a logic bug in this code, that could lead to null pointer
dereference when cvq is NULL. Fix this problem by changing logic
_and_ to logic _or_.

   >> CID 127480:  Null pointer dereferences  (FORWARD_NULL)
   >> Dereferencing null pointer "cvq".
   	if (!cvq && !cvq->vq) {
            ...
        }

Coverity issue: 127480

Fixes: 01ad44fd374f ("net/virtio: split Rx/Tx queue")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Yuanhan Liu July 5, 2016, 12:14 p.m. UTC | #1
On Tue, Jul 05, 2016 at 11:42:59AM +0000, Jianfeng Tan wrote:
> There is a logic bug in this code, that could lead to null pointer
> dereference when cvq is NULL. Fix this problem by changing logic
> _and_ to logic _or_.
> 
>    >> CID 127480:  Null pointer dereferences  (FORWARD_NULL)
>    >> Dereferencing null pointer "cvq".
>    	if (!cvq && !cvq->vq) {
>             ...
>         }
> 
> Coverity issue: 127480
> 
> Fixes: 01ad44fd374f ("net/virtio: split Rx/Tx queue")
> 
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

Applied to dpdk-next-virtio.

Thanks.

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 480daa3..828afef 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -166,7 +166,7 @@  virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 
 	ctrl->status = status;
 
-	if (!cvq && !cvq->vq) {
+	if (!cvq || !cvq->vq) {
 		PMD_INIT_LOG(ERR, "Control queue is not supported.");
 		return -1;
 	}