qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-block] [PATCH 21/25] nbd: Drop unexpected data for NBD_OPT_LIST


From: Max Reitz
Subject: [Qemu-block] [PATCH 21/25] nbd: Drop unexpected data for NBD_OPT_LIST
Date: Wed, 25 Feb 2015 13:08:34 -0500

When requesting the list of exports, no data should be sent. If data is
sent, the NBD server should not just inform the client of the invalid
request, but also drop the data.

Signed-off-by: Max Reitz <address@hidden>
---
 nbd.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/nbd.c b/nbd.c
index aa0925a..72e8243 100644
--- a/nbd.c
+++ b/nbd.c
@@ -199,6 +199,26 @@ static ssize_t read_sync(int fd, void *buffer, size_t size)
     return nbd_wr_sync(fd, buffer, size, true);
 }
 
+static ssize_t drop_sync(int fd, size_t size)
+{
+    ssize_t ret, dropped = size;
+    uint8_t *buffer = g_malloc(MIN(65536, size));
+
+    while (size > 0) {
+        ret = read_sync(fd, buffer, MIN(65536, size));
+        if (ret < 0) {
+            g_free(buffer);
+            return ret;
+        }
+
+        assert(ret <= size);
+        size -= ret;
+    }
+
+    g_free(buffer);
+    return dropped;
+}
+
 static ssize_t write_sync(int fd, void *buffer, size_t size)
 {
     int ret;
@@ -309,6 +329,9 @@ static int nbd_handle_list(NBDClient *client, uint32_t 
length)
 
     csock = client->sock;
     if (length) {
+        if (drop_sync(csock, length) != length) {
+            return -EIO;
+        }
         return nbd_send_rep(csock, NBD_REP_ERR_INVALID, NBD_OPT_LIST);
     }
 
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]