]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/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)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:50:49 +0000 (19:50 -0600)
commit8f3149b4c257dba10e464bd572f1da6aa00a4307
treead68b2dbe3cf592e6733d3c48e2a6ee7f2b90e55
parent5148c4f001c0a1d246a3c9779b3f7a4a94d58d14
usb: wusbcore: security: cast sizeof to int for comparison

BugLink: https://bugs.launchpad.net/bugs/1836287
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/usb/wusbcore/security.c