rng-egd: offset the point when repeatedly read from the buffer

The buffer content might be read out more than once, currently
we just repeatedly read the first data block, buffer offset is
missing.

Cc: qemu-stable@nongnu.org
Signed-off-by: Amos Kong <akong@redhat.com>
Message-id: 1385023371-8198-3-git-send-email-akong@redhat.com
Signed-off-by: Anthony Liguori <aliguori@amazon.com>
(cherry picked from commit 1eb1bd9eaf)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
Amos Kong 2013-11-21 16:42:51 +08:00 committed by Michael Roth
parent 0f6298786f
commit 7cfd037403
1 changed files with 3 additions and 1 deletions

View File

@ -91,12 +91,14 @@ static int rng_egd_chr_can_read(void *opaque)
static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size) static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size)
{ {
RngEgd *s = RNG_EGD(opaque); RngEgd *s = RNG_EGD(opaque);
size_t buf_offset = 0;
while (size > 0 && s->requests) { while (size > 0 && s->requests) {
RngRequest *req = s->requests->data; RngRequest *req = s->requests->data;
int len = MIN(size, req->size - req->offset); int len = MIN(size, req->size - req->offset);
memcpy(req->data + req->offset, buf, len); memcpy(req->data + req->offset, buf + buf_offset, len);
buf_offset += len;
req->offset += len; req->offset += len;
size -= len; size -= len;