Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: return correct errno code when krealloc fails

In function wusb_dev_sec_add(), variable result takes the return value.
Its value should be negative on failures. When function krealloc() is
called, an earlier check of variable result guarantees that the value of
result must not be less than "sizeof(*secd)", and result is not
reassigned when krealloc() returns a NULL pointer. As a result, a
positive value may be returned, which makes it impossible for the caller
of wusb_dev_sec_add() to detect the error. This patch fixes the bug by
assigning -ENOMEM to result when krealloc() returns NULL.

Signed-off-by: Pan Bian <bianpan2016@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Pan Bian and committed by
Greg Kroah-Hartman
fca0ca95 fd3ed14e

+1
+1
drivers/usb/wusbcore/security.c
··· 240 240 if (new_secd == NULL) { 241 241 dev_err(dev, 242 242 "Can't allocate space for security descriptors\n"); 243 + result = -ENOMEM; 243 244 goto out; 244 245 } 245 246 secd = new_secd;