From patchwork Tue Jun 6 02:51:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 103123 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp1214693qgd; Mon, 5 Jun 2017 20:01:21 -0700 (PDT) X-Received: by 10.55.197.68 with SMTP id p65mr29803420qki.45.1496718081282; Mon, 05 Jun 2017 20:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496718081; cv=none; d=google.com; s=arc-20160816; b=FfoMp+j72jKCRdGQ6jsJWM/WXkfwzx3IlXvxPpSQacJeciq9AvoH5/gnKJUZDXU0tn cU12T6dW6xNp2e9uIbbWoKrt4I6IEEki3v+8pxt1jLb75OffedvuUrQcTj+qDA9F2l1I 7fCyezazlevDq3ZrcRD+j4ucn8RdFutB1wafB+fh7X9ePYMKd1u7YepxqLOiTOCSfY8k gTf2nmVYPWrgJ41mT2BuAsprbLe7rR2+KkqwwoQjJ8zm0o6mRpG0SQigeNso7FZ6eNqS P/6996RxLHJelZMCE4pNs3eDLZN1mI82Ctmsmh61j6+Lu/M3ptWCWQmImIDN/wWTMbuh uI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=tnN5PjWnXrZHmstQSCAPbtnpJIlKheRwoczdU8H9oY0=; b=ik5poufOOWBfs9GFo0byqWAiKxvVeTuvEwO86ehCrvb4h9iXRuHMVKg8LpIT2A7rRo i88fstKFG5JwbVGNYmWwZY2OutT6R8frlNFOQt3eX7TY3gcPKXRHSlWUDVpLPmi1BpLs HOWnF5Gg1PBcQ/3soHkVYPBadADh30HxruhLYJr6uBxjU5VPoh17q1CnQuDmQoOCm1BL D2sgsKSgcL3RKR6AKirDp78t96WfTRSoKBeQUJ0DJOko+BHXjzB/Bk8cFTDgPT629TPb ovdzf02RgHhdwsH4lyTAroYFLoxGPz8jEyJsoHy5M4hzzXVE+eePfXHn8fnOsfgmraF0 H39w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gibson.dropbear.id.au; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k1si21268593qkd.325.2017.06.05.20.01.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 05 Jun 2017 20:01:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gibson.dropbear.id.au; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:35992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI4kA-00047p-Qm for patch@linaro.org; Mon, 05 Jun 2017 23:01:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI4ay-0003VE-8U for qemu-devel@nongnu.org; Mon, 05 Jun 2017 22:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dI4aw-0002z2-TW for qemu-devel@nongnu.org; Mon, 05 Jun 2017 22:51:48 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:52239) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dI4aw-0002xf-FV; Mon, 05 Jun 2017 22:51:46 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 3whbmq6r29z9sN8; Tue, 6 Jun 2017 12:51:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1496717499; bh=t5tn0E3cliu6Zcb7c2tfGvCToRuoCztOu26apeFI88s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YiM6rXL+xSLioCLMNycOQBx1gaH5VFebMIfyaFLWmdd1FhRLs+njBNhAlWJ+Lzbwl +Ixs63E+rVDffnVAKCvMMzJEATL021iM8PzqboPi4ZJZnBDinz4hoxIFvf7yF+soWu 5DtcIbU0c27DURnV2ULKx/GOUbHLt4RZC1SG5eO4= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 6 Jun 2017 12:51:27 +1000 Message-Id: <20170606025135.2685-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170606025135.2685-1-david@gibson.dropbear.id.au> References: <20170606025135.2685-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PULL 09/17] spapr_nvram: Check return value from blk_getlength() 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: mdroth@linux.vnet.ibm.com, David Gibson , qemu-ppc@nongnu.org, agraf@suse.de, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The blk_getlength() function can return an error value if the image size cannot be determined. Check for this rather than ploughing on and trying to g_malloc0() a negative number. (Spotted by Coverity, CID 1288484.) Signed-off-by: Peter Maydell Signed-off-by: David Gibson --- hw/nvram/spapr_nvram.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.9.4 diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index aa5d2c1..bc355a4 100644 --- a/hw/nvram/spapr_nvram.c +++ b/hw/nvram/spapr_nvram.c @@ -144,7 +144,15 @@ static void spapr_nvram_realize(VIOsPAPRDevice *dev, Error **errp) int ret; if (nvram->blk) { - nvram->size = blk_getlength(nvram->blk); + int64_t len = blk_getlength(nvram->blk); + + if (len < 0) { + error_setg_errno(errp, -len, + "could not get length of backing image"); + return; + } + + nvram->size = len; ret = blk_set_perm(nvram->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,