[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 06/18] nbd: Avoid magic number for NBD max name
From: |
Alex Bligh |
Subject: |
Re: [Qemu-devel] [PATCH 06/18] nbd: Avoid magic number for NBD max name size |
Date: |
Sat, 9 Apr 2016 11:35:19 +0100 |
On 8 Apr 2016, at 23:05, Eric Blake <address@hidden> wrote:
> Declare a constant and use that when determining if an export
> name fits within the constraints we are willing to support.
>
> Signed-off-by: Eric Blake <address@hidden>
> ---
> include/block/nbd.h | 2 ++
> nbd/client.c | 2 +-
> nbd/server.c | 4 ++--
> 3 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/include/block/nbd.h b/include/block/nbd.h
> index b86a976..3f047bf 100644
> --- a/include/block/nbd.h
> +++ b/include/block/nbd.h
> @@ -76,6 +76,8 @@ enum {
>
> /* Maximum size of a single READ/WRITE data buffer */
> #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024)
> +/* Maximum size of an export name */
> +#define NBD_MAX_NAME_SIZE 255
Given the standard is either likely to or does (can't
remember whether that patch is merged) document the
maximum supported export length as 4096, why not change
this to 4096?
Otherwise:
Reviewed-by: Alex Bligh <address@hidden>
>
> ssize_t nbd_wr_syncv(QIOChannel *ioc,
> struct iovec *iov,
> diff --git a/nbd/client.c b/nbd/client.c
> index c834587..00f9244 100644
> --- a/nbd/client.c
> +++ b/nbd/client.c
> @@ -210,7 +210,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **name,
> Error **errp)
> error_setg(errp, "incorrect option name length");
> return -1;
> }
> - if (namelen > 255) {
> + if (namelen > NBD_MAX_NAME_SIZE) {
> error_setg(errp, "export name length too long %" PRIu32, namelen);
> return -1;
> }
> diff --git a/nbd/server.c b/nbd/server.c
> index a10294e..5414c49 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -285,13 +285,13 @@ static int nbd_negotiate_handle_list(NBDClient *client,
> uint32_t length)
> static int nbd_negotiate_handle_export_name(NBDClient *client, uint32_t
> length)
> {
> int rc = -EINVAL;
> - char name[256];
> + char name[NBD_MAX_NAME_SIZE + 1];
>
> /* Client sends:
> [20 .. xx] export name (length bytes)
> */
> TRACE("Checking length");
> - if (length > 255) {
> + if (length >= sizeof(name)) {
> LOG("Bad length received");
> goto fail;
> }
> --
> 2.5.5
>
>
--
Alex Bligh
- Re: [Qemu-devel] [PATCH 15/18] nbd: Implement NBD_OPT_GO on server, (continued)
- [Qemu-devel] [PATCH 13/18] nbd: Support shorter handshake, Eric Blake, 2016/04/08
- [Qemu-devel] [PATCH 07/18] nbd: Treat flags vs. command type as separate fields, Eric Blake, 2016/04/08
- [Qemu-devel] [RFC PATCH 17/18] nbd: Implement NBD_CMD_WRITE_ZEROES on server, Eric Blake, 2016/04/08
- [Qemu-devel] [PATCH 06/18] nbd: Avoid magic number for NBD max name size, Eric Blake, 2016/04/08
- Re: [Qemu-devel] [PATCH 06/18] nbd: Avoid magic number for NBD max name size,
Alex Bligh <=
- [Qemu-devel] [RFC PATCH 18/18] nbd: Implement NBD_CMD_WRITE_ZEROES on client, Eric Blake, 2016/04/08
- [Qemu-devel] [PATCH 16/18] nbd: Support NBD_CMD_CLOSE, Eric Blake, 2016/04/08