summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-01-03 12:40:06 +0100
committerPeter Wu <peter@lekensteyn.nl>2015-01-06 17:28:23 +0100
commitb55e68f1c1445c218ad9bff2e0f7d3d63aada2a8 (patch)
tree89ad534197af5d77fcf52e2490914d8d8f384d73
parent81cc493e43b95bbe4c07981cb959fc65d608ed04 (diff)
downloadqemu-b55e68f1c1445c218ad9bff2e0f7d3d63aada2a8.tar.gz
block/dmg: validate chunk size to avoid overflow
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 <peter@lekensteyn.nl>
-rw-r--r--block/dmg.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/block/dmg.c b/block/dmg.c
index 49132499cc..5f6976b25b 100644
--- a/block/dmg.c
+++ b/block/dmg.c
@@ -319,7 +319,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;
}
@@ -379,6 +379,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);