Re: [PATCH 4.9 05/29] usbnet: make sure no NULL pointer is passed through

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

> From: Oliver Neukum <oneukum@xxxxxxxx>
> 
> commit 6c22fce07c97f765af1808ec3be007847e0b47d1 upstream.
> 
> Coverity reports:
> 
> ** CID 751368:  Null pointer dereferences  (FORWARD_NULL)
> /drivers/net/usb/usbnet.c: 1925 in __usbnet_read_cmd()
> 
> ________________________________________________________________________________________________________

There's something wrong here. Changelog is cut, so signed-offs are
missing. It is wrong in git, too.

There's something wrong with the whitespace in the patch (indentation
by 4 spaces instead of tab), too.

Best regards,
								Pavel
								
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
> @@ -1960,8 +1960,13 @@ static int __usbnet_read_cmd(struct usbn
>  	err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
>  			      cmd, reqtype, value, index, buf, size,
>  			      USB_CTRL_GET_TIMEOUT);
> -	if (err > 0 && err <= size)
> -		memcpy(data, buf, err);
> +	if (err > 0 && err <= size) {
> +        if (data)
> +            memcpy(data, buf, err);
> +        else
> +            netdev_dbg(dev->net,
> +                "Huh? Data requested but thrown away.\n");
> +    }
>  	kfree(buf);
>  out:
>  	return err;
> @@ -1982,7 +1987,13 @@ static int __usbnet_write_cmd(struct usb
>  		buf = kmemdup(data, size, GFP_KERNEL);
>  		if (!buf)
>  			goto out;
> -	}
> +	} else {
> +        if (size) {
> +            WARN_ON_ONCE(1);
> +            err = -EINVAL;
> +            goto out;
> +        }
> +    }
>  
>  	err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
>  			      cmd, reqtype, value, index, buf, size,
> 

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux