Skip to contentSkip to conversation

fix rng-egd backend

PATCH In review Amos Kong 2 participants 4 messages Nov 21, 2013

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

cover fix rng-egd backend

The first is a trivial cleanup, the second patch fixes a memcpy bug in reading data from chardev to request data buffer.

Amos Kong (2):
rng-egd: remove redundant free
rng-egd: offset the point when repeatedly read from the buffer

 backends/rng-egd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 rng-egd: remove redundant free

We didn't set default chr_name, the free is redundant.

---
 backends/rng-egd.c | 1 -
 1 file changed, 1 deletion(-)
backends/rng-egd.c +0 -1
index 9e5a536..6f56f9e 100644
@@ -167,7 +167,6 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
     if (b->opened) {
         error_set(errp, QERR_PERMISSION_DENIED);
     } else {
-        g_free(s->chr_name);
         s->chr_name = g_strdup(value);
     }
 }
Signature · 1 line
1.8.3.1
author
#2 lore raw

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

In reply to Amos Kong

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

---
 backends/rng-egd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
backends/rng-egd.c +3 -1
index 6f56f9e..25bb3b4 100644
@@ -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;
 
Signature · 1 line
1.8.3.1
Reviewed-by on the v1 series
#3 lore raw
In reply to Amos Kong

Il 21/11/2013 09:42, Amos Kong ha scritto:

Quoted 10 lines

The first is a trivial cleanup, the second patch fixes a memcpy bug in reading data from chardev to request data buffer.

Amos Kong (2):
rng-egd: remove redundant free
rng-egd: offset the point when repeatedly read from the buffer

 backends/rng-egd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)