Skip to content

Commit

Permalink
rng-egd: offset the point when repeatedly read from the buffer
Browse files Browse the repository at this point in the history
The buffer content might be read out more than once, currently
we just repeatedly read the first data block, buffer offset is
missing.

Cc: [email protected]
Signed-off-by: Amos Kong <[email protected]>
Message-id: [email protected]
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
amoskong authored and Anthony Liguori committed Nov 21, 2013
1 parent 5e490b6 commit 1eb1bd9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backends/rng-egd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
RngEgd *s = RNG_EGD(opaque);
size_t buf_offset = 0;

while (size > 0 && s->requests) {
RngRequest *req = s->requests->data;
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;
size -= len;

Expand Down

0 comments on commit 1eb1bd9

Please sign in to comment.