[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/19] nbd: Drop unexpected data for NBD_OPT_LIST
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 12/19] nbd: Drop unexpected data for NBD_OPT_LIST |
Date: |
Wed, 18 Mar 2015 12:24:59 +0100 |
From: Max Reitz <address@hidden>
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>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
nbd.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
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);
}
--
2.3.0
- [Qemu-devel] [PULL 03/19] qemu-nbd: Detect unused partitions by system == 0, (continued)
- [Qemu-devel] [PULL 03/19] qemu-nbd: Detect unused partitions by system == 0, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 02/19] util/uri: Add overflow check to rfc3986_parse_port, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 08/19] nbd: Fix potential signed overflow issues, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 09/19] nbd: Set block size to BDRV_SECTOR_SIZE, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 10/19] nbd: Fix nbd_receive_options(), Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 06/19] nbd: Handle blk_getlength() failure, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 07/19] qemu-nbd: fork() can fail, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 14/19] build: pass .d file name to scripts/make_device_config.sh, fix makefile target, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 11/19] nbd: Fix interpretation of the export flags, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 15/19] virtio-scsi: Fix assert in virtio_scsi_push_event, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 12/19] nbd: Drop unexpected data for NBD_OPT_LIST,
Paolo Bonzini <=
- [Qemu-devel] [PULL 18/19] virtio-scsi-dataplane: fix memory leak in virtio_scsi_vring_init, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 19/19] exec: Respect as_tranlsate_internal length clamp, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 16/19] kvm: fix ioeventfd endianness on bi-endian architectures, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 17/19] profiler: Reenable built-in profiler, Paolo Bonzini, 2015/03/18
- [Qemu-devel] [PULL 13/19] coroutine-io: Return -errno in case of error, Paolo Bonzini, 2015/03/18
- Re: [Qemu-devel] [PULL 00/19] Misc bugfixes for 2.3.0-rc1, Peter Maydell, 2015/03/19