qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sheepdog: discard the payload if the header is invalid
@ 2015-09-01  1:29 Liu Yuan
  2015-09-01  1:51 ` Jeff Cody
  0 siblings, 1 reply; 4+ messages in thread
From: Liu Yuan @ 2015-09-01  1:29 UTC (permalink / raw)
  To: sheepdog-ng; +Cc: Kevin Wolf, Jeff Cody, qemu-devel, Stefan Hajnoczi

From: Liu Yuan <liuyuan@cmss.chinamobile.com>

We need to discard the payload if we get a invalid header due to whatever reason
to avoid data stream curruption. For e.g., the response consists of header plus
data payload. If we simply read the header then the data payload is left in the
socket buffer and the next time we would read the garbage data and currupt the
whole connection.

Cc: qemu-devel@nongnu.org
Cc: Jeff Cody <jcody@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Liu Yuan <liuyuan@cmss.chinamobile.com>
---
 block/sheepdog.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 9585beb..9ed3458 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -794,6 +794,14 @@ static void coroutine_fn aio_read_response(void *opaque)
         }
     }
     if (!aio_req) {
+        if (rsp.data_length) {
+            void *garbage = g_malloc(rsp.data_length);
+            ret = qemu_co_recv(fd, garbage, rsp.data_length);
+            if (ret != rsp.data_length) {
+                error_report("failed to discard the data, %s", strerror(errno));
+            }
+            g_free(garbage);
+        }
         error_report("cannot find aio_req %x", rsp.id);
         goto err;
     }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-01 10:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-01  1:29 [Qemu-devel] [PATCH] sheepdog: discard the payload if the header is invalid Liu Yuan
2015-09-01  1:51 ` Jeff Cody
2015-09-01  2:05   ` Liu Yuan
2015-09-01 10:23     ` Liu Yuan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).