提交 8de85386 编写于 作者: P Peter Krempa

qemu: blockPeek: Enforce buffer filling

Documentation states:

"'offset' and 'size' represent an area which must lie entirely within
the device or file." Enforce the that the buffer lies within fully.
上级 f767d53d
...@@ -11416,6 +11416,7 @@ qemuDomainBlockPeek(virDomainPtr dom, ...@@ -11416,6 +11416,7 @@ qemuDomainBlockPeek(virDomainPtr dom,
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
virDomainObjPtr vm; virDomainObjPtr vm;
char *tmpbuf = NULL; char *tmpbuf = NULL;
ssize_t nread;
int ret = -1; int ret = -1;
virCheckFlags(0, -1); virCheckFlags(0, -1);
...@@ -11442,9 +11443,16 @@ qemuDomainBlockPeek(virDomainPtr dom, ...@@ -11442,9 +11443,16 @@ qemuDomainBlockPeek(virDomainPtr dom,
if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0) if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0)
goto cleanup; goto cleanup;
if (virStorageFileRead(disk->src, offset, size, &tmpbuf) < 0) if ((nread = virStorageFileRead(disk->src, offset, size, &tmpbuf)) < 0)
goto cleanup; goto cleanup;
if (nread < size) {
virReportError(VIR_ERR_INVALID_ARG,
_("'%s' starting from %llu has only %zd bytes available"),
path, offset, nread);
goto cleanup;
}
memcpy(buffer, tmpbuf, size); memcpy(buffer, tmpbuf, size);
ret = 0; ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册