]> git.itanic.dy.fi Git - linux-stable/commit
usb: wusbcore: security: cast sizeof to int for comparison
authorJulia Lawall <Julia.Lawall@lip6.fr>
Sun, 1 Jul 2018 17:32:04 +0000 (19:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Oct 2018 07:09:24 +0000 (09:09 +0200)
commit5c25cf14849f73e6b2dc1b008bb5eeb5265c6ee0
treefcb5fb0e8ecfe931cee1863e63f38c6c50f6a93e
parentf5ba8279ebb621504b3cc116f998d819a61d2f65
usb: wusbcore: security: cast sizeof to int for comparison

[ Upstream commit d3ac5598c5010a8999978ebbcca3b1c6188ca36b ]

Comparing an int to a size, which is unsigned, causes the int to become
unsigned, giving the wrong result.  usb_get_descriptor can return a
negative error code.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
int x;
expression e,e1;
identifier f;
@@

*x = f(...);
... when != x = e1
    when != if (x < 0 || ...) { ... return ...; }
*x < sizeof(e)
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/wusbcore/security.c