summaryrefslogtreecommitdiffstats
path: root/nbd.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2015-02-25 13:08:34 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2015-03-18 12:07:16 +0100
commit0379f474ddebfc69f42fa8231d86687cf29d997b (patch)
tree5cd0202229ad133d32add23d1100443514738c19 /nbd.c
parent48c7d80de8863e3436b3b5d5676018b2afaec161 (diff)
downloadhqemu-0379f474ddebfc69f42fa8231d86687cf29d997b.zip
hqemu-0379f474ddebfc69f42fa8231d86687cf29d997b.tar.gz
nbd: Drop unexpected data for NBD_OPT_LIST
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 <mreitz@redhat.com> Message-Id: <1424887718-10800-22-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'nbd.c')
-rw-r--r--nbd.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/nbd.c b/nbd.c
index 563e820..91b7d56 100644
--- a/nbd.c
+++ b/nbd.c
@@ -193,6 +193,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;
@@ -303,6 +323,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);
}
OpenPOWER on IntegriCloud