[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
- [Qemu-block] [PATCH 14/25] coroutine: Add co_yield_timeout(), (continued)
- [Qemu-block] [PATCH 14/25] coroutine: Add co_yield_timeout(), Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 15/25] coroutine-io: Return -errno in case of error, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 07/25] nbd: Add "failed to open export" error message, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 13/25] nbd: Enforce sector alignment, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 12/25] nbd: Set block size to BDRV_SECTOR_SIZE, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 11/25] qemu-nbd: Fix and improve input verification, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 22/25] iotests: Add _timeout function, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 20/25] block/nbd: Comment on discard/flush silently failing, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 16/25] coroutine-io: Add I/O functions with timeout, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 23/25] iotests: Add test for invalid qemu-nbd parameters, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 21/25] nbd: Drop unexpected data for NBD_OPT_LIST,
Max Reitz <=
- [Qemu-block] [PATCH 25/25] iotests: Add test for a non-existing NBD export, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 19/25] nbd: Fix interpretation of the export flags, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 18/25] nbd: Fix nbd_receive_options(), Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 17/25] nbd: Employ timeouts, Max Reitz, 2015/02/25
- Re: [Qemu-block] [PATCH 00/25] nbd: Several fixes, Max Reitz, 2015/02/25
- [Qemu-block] [PATCH 24/25] iotests: Add test for issuing discard over NBD, Max Reitz, 2015/02/25