]> Git Repo - qemu.git/commitdiff
block/dmg: validate chunk size to avoid overflow
authorPeter Wu <[email protected]>
Tue, 6 Jan 2015 17:48:08 +0000 (18:48 +0100)
committerKevin Wolf <[email protected]>
Fri, 6 Feb 2015 16:24:21 +0000 (17:24 +0100)
Previously the chunk size was not checked, allowing for a large memory
allocation. This patch checks whether the chunks size is within the
resource fork length, and whether the resource fork is below the
trailer of the dmg file.

Signed-off-by: Peter Wu <[email protected]>
Reviewed-by: John Snow <[email protected]>
Message-id: 1420566495[email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
block/dmg.c

index 4f56227fc5f55593049ea776974cb5a603b6dd67..5c2c2c231d78a4efec1fe81618b2fb2089c0d0bb 100644 (file)
@@ -317,7 +317,7 @@ static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds,
         ret = read_uint32(bs, offset, &count);
         if (ret < 0) {
             goto fail;
-        } else if (count == 0) {
+        } else if (count == 0 || count > info_end - offset) {
             ret = -EINVAL;
             goto fail;
         }
@@ -377,6 +377,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
     if (ret < 0) {
         goto fail;
     }
+    if (rsrc_fork_offset >= offset ||
+        rsrc_fork_length > offset - rsrc_fork_offset) {
+        ret = -EINVAL;
+        goto fail;
+    }
     if (rsrc_fork_length != 0) {
         ret = dmg_read_resource_fork(bs, &ds,
                                      rsrc_fork_offset, rsrc_fork_length);
This page took 0.02664 seconds and 4 git commands to generate.