mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 21:47:16 +03:00
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.
This commit is contained in:
parent
f767d53dbe
commit
8de85386db
@ -11416,6 +11416,7 @@ qemuDomainBlockPeek(virDomainPtr dom,
|
||||
virDomainDiskDefPtr disk = NULL;
|
||||
virDomainObjPtr vm;
|
||||
char *tmpbuf = NULL;
|
||||
ssize_t nread;
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
@ -11442,9 +11443,16 @@ qemuDomainBlockPeek(virDomainPtr dom,
|
||||
if (qemuDomainStorageFileInit(driver, vm, disk->src) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virStorageFileRead(disk->src, offset, size, &tmpbuf) < 0)
|
||||
if ((nread = virStorageFileRead(disk->src, offset, size, &tmpbuf)) < 0)
|
||||
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);
|
||||
|
||||
ret = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user