usb: gadget: fastboot: correctly cap rx_bytes_expected() result
PATCH 1/1 usb: gadget: fastboot: correctly cap rx_bytes_expected() result
The function only ever returns an unsigned value and fastboot.download_{size,bytes} are both unsigned values too.
Storing their difference into an int may possibly lead to misbehavior, so fix the types to ensure no overflow can happen.
Signed-off-by Ahmad Fatoum <[email protected]>
--- drivers/usb/gadget/function/f_fastboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/function/f_fastboot.c +3 -3
@@ -445,10 +445,10 @@ static int fastboot_write_usb(struct fastboot *fb, const char *buffer, unsignedreturn 0 ; } -static int rx_bytes_expected (struct f_fastboot *f_fb) +static unsigned rx_bytes_expected (struct f_fastboot *f_fb) { -int remaining = f_fb->fastboot.download_size - - f_fb->fastboot.download_bytes; +size_t remaining = f_fb->fastboot.download_size + - f_fb->fastboot.download_bytes;if (remaining >=EP_BUFFER_SIZE )return EP_BUFFER_SIZE ;
Signature · 1 line
2.47.3
Sascha Hauer
AppliedQuoted 8 lines · Ahmad Fatoum
The function only ever returns an unsigned value and fastboot.download_{size,bytes} are both unsigned values too.
Storing their difference into an int may possibly lead to misbehavior, so fix the types to ensure no overflow can happen.
[...]
Applied, thanks!
[1/1] usb: gadget: fastboot: correctly cap rx_bytes_expected() result
https://git.pengutronix.de/cgit/barebox/commit/?id=0d9d229fd497 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>