Skip to contentSkip to conversation

Improve block range checks

PATCH New Kevin Wolf 1 participant 1 message May 8, 2009

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 Improve block range checks

This patch makes the range checks for block requests more strict: It fixes a potential integer overflow and checks for negative offsets. Also, it adds the check for compressed writes.

---
 block.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
block.c +6 -1
index 3d1223d..acb8976 100644
@@ -578,7 +578,10 @@ static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset,
 
     len = bdrv_getlength(bs);
 
-    if ((offset + size) > len)
+    if (offset < 0)
+        return -EIO;
+
+    if ((offset > len) || (len - offset < size))
         return -EIO;
 
     return 0;
@@ -1150,6 +1153,8 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
         return -ENOMEDIUM;
     if (!drv->bdrv_write_compressed)
         return -ENOTSUP;
+    if (bdrv_check_request(bs, sector_num, nb_sectors))
+        return -EIO;
     return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
 }
 
Signature · 1 line
1.6.0.6