From c43e736c0ccd26fbfea11c19d5140ea1cc30d90d Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Mon, 21 May 2012 13:59:43 +0200 Subject: libpayload: Fix an integer overflow in USB mass storage Change-Id: I3d618497016478ea727c520e866d27dbc3ebf9af Signed-off-by: Nico Huber Reviewed-on: http://review.coreboot.org/1070 Reviewed-by: Mathias Krause Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- payloads/libpayload/drivers/usb/usbmsc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'payloads/libpayload/drivers/usb') diff --git a/payloads/libpayload/drivers/usb/usbmsc.c b/payloads/libpayload/drivers/usb/usbmsc.c index d39c784c30..8d5773629f 100644 --- a/payloads/libpayload/drivers/usb/usbmsc.c +++ b/payloads/libpayload/drivers/usb/usbmsc.c @@ -360,6 +360,9 @@ read_capacity (usbdev_t *dev) } printf (" %d %d-byte sectors (%d MB)\n", MSC_INST (dev)->numblocks, MSC_INST (dev)->blocksize, + /* round down high block counts to avoid integer overflow */ + MSC_INST (dev)->numblocks > 1000000 + ? (MSC_INST (dev)->numblocks / 1000) * MSC_INST (dev)->blocksize / 1000 : MSC_INST (dev)->numblocks * MSC_INST (dev)->blocksize / 1000 / 1000); } -- cgit v1.2.3