From patchwork Mon Jul 23 20:16:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10540983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C44C112E for ; Mon, 23 Jul 2018 21:04:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BE80283CF for ; Mon, 23 Jul 2018 21:04:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 807F728492; Mon, 23 Jul 2018 21:04:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2601C283CF for ; Mon, 23 Jul 2018 21:04:54 +0000 (UTC) Received: from localhost ([::1]:36611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhi0j-0006Sx-8O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 Jul 2018 17:04:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhJd-0002qQ-AL for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhhJc-0004ef-AU for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:20:21 -0400 Received: from mail-oi0-x22e.google.com ([2607:f8b0:4003:c06::22e]:45703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhhJb-0004eG-Q4; Mon, 23 Jul 2018 16:20:19 -0400 Received: by mail-oi0-x22e.google.com with SMTP id q11-v6so3449839oic.12; Mon, 23 Jul 2018 13:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2V5LQCR6NqPwZ27Qk2WwhMBjOF4RGe0+VxG6IDpBZv0=; b=MPeiOo1iKQl6xrR/aMkcr6S1Wik9gwudLljrUQPuXKNDxPWbJlaTif0yxPLdfGPrmm izurVH4TVxTqw6yjGhXxY8bGx0iVHn7D9vNA0n1fav0rEJPcn7b0qm8NE4WhBlh1D5pK lz3Pz/rlLiFfi2cMkji3j+uYHktxyysjt2QGFd8MZ5uJoVC24/9fOHWc8rWf133I+ulR PDFhL8VWPsgf3hvI90XRfIZ92Tk7PyzBPr78CZ3jyxORhRTaZAsDDM2AOauijM919Z2S 7qnkX02T2e00mc/Q2R8JB/kWIrY56/EXRS8KtBC/G299X3t2wYKM3O0toMsJmoJR02i3 TuQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2V5LQCR6NqPwZ27Qk2WwhMBjOF4RGe0+VxG6IDpBZv0=; b=AAThuuA6t06ZGySapM6KznuSmeREQ+vv2sZzDLgOIZt1BN7LFWNqDanShTZ6Ov1xWg 2Q3E4VmYNgi6HvEdne8ZYdbDYgq81uRay5oseRFa9j0sdffNQgvV16HU+SPlPHGSDWrn pO8ZjYy9t/1oKpvATi+fRWKOzp/rV5c4roFPm3jC3lcShrKZ3+L9UnKa5Onhq4Ujb2oq 2hu5z25mdcL6K8S+YYEEVH9k4bR9CTMkaa7+/FtNJ55srGyaVOHb144M/zHir+C9N6wS KOvRNCiihNqS5z1XJ0mpUZimmtK8Ualb1KqD1DlDcQ20atFgmwIKonvOUycH+PvWCrCr pqVQ== X-Gm-Message-State: AOUpUlGZgehQN0Kd/Qff1BKSJaqx9mN9W5ns5ZwstoiGHPZTkVO7duPy m/muBNYxxVsseTF9qvSgXLImpLjnOkM= X-Google-Smtp-Source: AAOMgpcZLxwahDlfXle1OB3jUblXjH+/TcgXJC8+qZ6bOoJ81E7IwrYeUg+t0r8qnksXAjfmabz1IA== X-Received: by 2002:aca:171a:: with SMTP id j26-v6mr279878oii.277.1532377218685; Mon, 23 Jul 2018 13:20:18 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id e125-v6sm9836179oig.4.2018.07.23.13.20.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 13:20:17 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 15:16:13 -0500 Message-Id: <20180723201748.25573-5-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> References: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22e Subject: [Qemu-devel] [PATCH 04/99] nbd/client: Fix error messages during NBD_INFO_BLOCK_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: qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake A missing space makes for poor error messages, and sizes can't go negative. Also, we missed diagnosing a server that sends a maximum block size less than the minimum. Fixes: 081dd1fe CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Message-Id: <20180501154654.943782-1-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy (cherry picked from commit e475d108f1b3d3163f0affea67cdedbe5fc9752b) Signed-off-by: Michael Roth --- nbd/client.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index b9e175d1c2..3523c863fe 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -435,8 +435,8 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname, } be32_to_cpus(&info->min_block); if (!is_power_of_2(info->min_block)) { - error_setg(errp, "server minimum block size %" PRId32 - "is not a power of two", info->min_block); + error_setg(errp, "server minimum block size %" PRIu32 + " is not a power of two", info->min_block); nbd_send_opt_abort(ioc); return -1; } @@ -450,8 +450,8 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname, be32_to_cpus(&info->opt_block); if (!is_power_of_2(info->opt_block) || info->opt_block < info->min_block) { - error_setg(errp, "server preferred block size %" PRId32 - "is not valid", info->opt_block); + error_setg(errp, "server preferred block size %" PRIu32 + " is not valid", info->opt_block); nbd_send_opt_abort(ioc); return -1; } @@ -462,6 +462,12 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname, return -1; } be32_to_cpus(&info->max_block); + if (info->max_block < info->min_block) { + error_setg(errp, "server maximum block size %" PRIu32 + " is not valid", info->max_block); + nbd_send_opt_abort(ioc); + return -1; + } trace_nbd_opt_go_info_block_size(info->min_block, info->opt_block, info->max_block); break;