qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block/parallels.c: avoid integer overflow in allocate_clusters()
@ 2017-03-31 13:13 Peter Maydell
  2017-03-31 13:27 ` Philippe Mathieu-Daudé
  2017-03-31 13:47 ` Max Reitz
  0 siblings, 2 replies; 12+ messages in thread
From: Peter Maydell @ 2017-03-31 13:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: patches, Stefan Hajnoczi, Denis V. Lunev, Kevin Wolf, Max Reitz,
	qemu-block

Coverity (CID 1307776) points out that in the multiply:
  space = to_allocate * s->tracks;
we are trying to calculate a 64 bit result but the types
of to_allocate and s->tracks mean that we actually calculate
a 32 bit result. Add an explicit cast to force a 64 bit
multiply.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
NB: compile-and-make-check tested only...
---
 block/parallels.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/parallels.c b/block/parallels.c
index 4173b3f..3886c30 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -206,7 +206,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
     }
 
     to_allocate = DIV_ROUND_UP(sector_num + *pnum, s->tracks) - idx;
-    space = to_allocate * s->tracks;
+    space = (int64_t)to_allocate * s->tracks;
     if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_BITS) {
         int ret;
         space += s->prealloc_size;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-03-31 21:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-31 13:13 [Qemu-devel] [PATCH] block/parallels.c: avoid integer overflow in allocate_clusters() Peter Maydell
2017-03-31 13:27 ` Philippe Mathieu-Daudé
2017-03-31 13:28   ` Peter Maydell
2017-03-31 13:40   ` Eduardo Habkost
2017-03-31 16:18     ` Stefan Hajnoczi
2017-03-31 17:10       ` Eduardo Habkost
2017-03-31 13:47 ` Max Reitz
2017-03-31 14:54   ` Denis V. Lunev
2017-03-31 14:56     ` Max Reitz
2017-03-31 15:00       ` Denis V. Lunev
2017-03-31 16:20   ` Stefan Hajnoczi
2017-03-31 16:41     ` Max Reitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).