From patchwork Fri Apr 8 22:05:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8786471 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EFF21C0553 for ; Fri, 8 Apr 2016 22:08:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5D8EF202E9 for ; Fri, 8 Apr 2016 22:08:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A66ED20218 for ; Fri, 8 Apr 2016 22:08:47 +0000 (UTC) Received: from localhost ([::1]:58532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoea6-0006Zl-SQ for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Apr 2016 18:08:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoeXn-0001rg-Jl for qemu-devel@nongnu.org; Fri, 08 Apr 2016 18:06:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoeXm-0007Uh-PP for qemu-devel@nongnu.org; Fri, 08 Apr 2016 18:06:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36101) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoeXk-0007Sw-Fy; Fri, 08 Apr 2016 18:06:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3071FC05E16C; Fri, 8 Apr 2016 22:06:20 +0000 (UTC) Received: from red.redhat.com (ovpn-113-199.phx2.redhat.com [10.3.113.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u38M67UC029137; Fri, 8 Apr 2016 18:06:19 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Apr 2016 16:05:46 -0600 Message-Id: <1460153158-21612-7-git-send-email-eblake@redhat.com> In-Reply-To: <1460153158-21612-1-git-send-email-eblake@redhat.com> References: <1460153158-21612-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/18] nbd: Avoid magic number for NBD max name size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Paolo Bonzini , "open list:Block layer core" , alex@alex.org.uk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Alex Bligh --- 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 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; }