qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Yuan <namei.unix@gmail.com>
To: sheepdog-ng@googlegroups.com
Cc: Kevin Wolf <kwolf@redhat.com>, Jeff Cody <jcody@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH] sheepdog: discard the payload if the header is invalid
Date: Tue,  1 Sep 2015 09:29:31 +0800	[thread overview]
Message-ID: <1441070971-22535-1-git-send-email-namei.unix@gmail.com> (raw)

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

             reply	other threads:[~2015-09-01  1:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01  1:29 Liu Yuan [this message]
2015-09-01  1:51 ` [Qemu-devel] [PATCH] sheepdog: discard the payload if the header is invalid Jeff Cody
2015-09-01  2:05   ` Liu Yuan
2015-09-01 10:23     ` Liu Yuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441070971-22535-1-git-send-email-namei.unix@gmail.com \
    --to=namei.unix@gmail.com \
    --cc=jcody@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sheepdog-ng@googlegroups.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).