diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-12-27 18:43:13 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-12-27 18:43:13 +0100 |
commit | 41fd83773361923f668f54796ff563660b77e96c (patch) | |
tree | f1883d71acdddbf3365c0c33bcf5f6b1ceb612e9 /block/dmg.c | |
parent | c090e0700e4403d084423f56990b85749c62a829 (diff) | |
download | qemu-41fd83773361923f668f54796ff563660b77e96c.tar.gz |
block/dmg: validate more offsets and lengthsblock-dmg-2.3
Patch "block/dmg: validate chunk size to avoid overflow" is not enough
to catch boundary issues as "info_length" was unchecked. This patch
ensures that the read boundaries are valid.
Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'block/dmg.c')
-rw-r--r-- | block/dmg.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/block/dmg.c b/block/dmg.c index b84ba7e690..dd8551cf27 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -450,6 +450,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (ds.data_fork_offset > offset) { + ret = -EINVAL; + goto fail; + } /* offset of resource fork (RsrcForkOffset) */ ret = read_uint64(bs, offset + 0x28, &rsrc_fork_offset); @@ -460,6 +464,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; + } /* offset of property list (XMLOffset) */ ret = read_uint64(bs, offset + 0xd8, &plist_xml_offset); if (ret < 0) { @@ -469,6 +478,11 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, if (ret < 0) { goto fail; } + if (plist_xml_offset >= offset || + plist_xml_length > offset - plist_xml_offset) { + ret = -EINVAL; + goto fail; + } ret = read_uint64(bs, offset + 0x1ec, (uint64_t *)&bs->total_sectors); if (ret < 0) { goto fail; |