From patchwork Tue Oct 8 16:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 833584 Delivered-To: patch@linaro.org Received: by 2002:adf:a1d9:0:b0:367:895a:4699 with SMTP id v25csp395247wrv; Tue, 8 Oct 2024 09:48:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUENdT8439mIZS24bb6gY7FFccFYojKMXGpAO6O49C5WkCLKA6aT45Z4OF3BU5Qu9QbWBGB3Q==@linaro.org X-Google-Smtp-Source: AGHT+IHm10VEPgW7Gv5deUa4vshcuTO2YRXl8zgjUdKVZ0yWWId426ZfAGQSSBD18tEWbDxHNL+2 X-Received: by 2002:a05:6214:3282:b0:6ca:756d:68a8 with SMTP id 6a1803df08f44-6cb9a2f5852mr208536786d6.15.1728406112953; Tue, 08 Oct 2024 09:48:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728406112; cv=none; d=google.com; s=arc-20240605; b=LSnF7nFPRKBGDJ4LvcllZykTF304f5J/YrIeVCLfljEjKTstDgYS7JaY/jt4Utdmx2 fGKWY+J/HP9xltzVOLM9F5csUQEc4EBH3t2wNGJzel7Gn0Uo2GhgxZ8t/GPa0VY8jQGG QC2+eDZOYJzXg7K4WQYT6HFhrBeoF4WnxOECIIA/odsnnUyBUp8+UVeC5IxCxXjXVVSC eYz4GJZvxZNc67jk3UisVevcgeV1gZTwn2SzeDxucdqMdBngjC/EvHR8ciaL/HcKNzW2 c4NXVgmpwOTKXOjiE1aQjODtUEFtsE33MpoSPGIaaE10JIHQfy137GeAbQUfWL20SJjj tdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oy11i6KMMYbTDLbggIWsMEmjce0qeq1GCqydkwW53Z4=; fh=GeYAnZnQ/hHVwF5xM/bbpAEr03LDLLn0NlNLYifVRZ0=; b=LGhbkBe9xrHBBdHJy1FuBCp8AcPesKzfHyl3TtpsNeHZ1urL9ONdntyotpLC58e0Iz DrE7VK57x8kHXsJdIl2UkLi04t8yrdWMviNEEuuICJ/qzOXpXSw4hiTVk2JbhWqr/48p JgPB1K8TR44AJ4Sxm77K+ilVGwLlD3tIUaj8XRHRe84TJwefmL7p4X0voW/9PuIvdWNK j9feQMbFhY9SNu16Dmg/uFbLdirxmRpHm4LsgcPquRFcnLH5RnUttqg4limVQPsdOBVJ sevWdK2u6ejSow7CPXaEPek7QzMjYONedkmcaxYdtYqsVAWRbymOW2/lCkyn961tMp35 YN2A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1nij1Xk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6cbc65a8b05si9106826d6.493.2024.10.08.09.48.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Oct 2024 09:48:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1nij1Xk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syDMi-0003BY-5H; Tue, 08 Oct 2024 12:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syDMg-0003A2-68 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:14 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syDMd-00038M-QK for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:13 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-37ccfbbd467so4109328f8f.0 for ; Tue, 08 Oct 2024 09:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728406030; x=1729010830; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oy11i6KMMYbTDLbggIWsMEmjce0qeq1GCqydkwW53Z4=; b=z1nij1Xk4OWcHCA2SIBISZmZ4YTQRM8qKQPRmMN+KgmAp8Qrye7DbpTXluhZv04g4a PlSIjVyprQfcTeZYKTiQZNmaEEhVHKcDHV2p3aYDT0D5zCpBh+lNTpht7xVcsr8erhlG XYmaPsSF2D/KrHJJbN2In7z2cVL4w2HhiEVumOoPSTkf6xuXFh4bT85SmDaF/Ydu6chJ 7MTULk8giPDSf8cesjGzLpkWWwkybA2h0lVORKEf7i7s3+u2hiyan/cWvZSlR+7L56tL Oik2DZuSEDk7YsMdxSLv9rEeeAaOz5r6Q0dIks+M/VxfxT3Y48+27lKILTYPNUHGZp9H 3LGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406030; x=1729010830; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oy11i6KMMYbTDLbggIWsMEmjce0qeq1GCqydkwW53Z4=; b=SQGNn883Tq6M0XhkEmMof5mZeC5YcuFbLmIwoa3Ii0A24xJZt6DhLnJtdyyEwXpI72 JQW5c/1DAOsKVVIfhA2VFkeGZDDGxcPQLvssDjCacabRqAe7IjQlw/266Bcti6TijYMf /gYLGk+n3AmJKdIo1SkcXAd0V9sTJiLpoYhTTYJxGGzMx+tyk0Q00W0SYnZQM3yXROI1 yl11mXbrlfY3x11NMnfK4+CUdxTlb6fuT6hFAbWVNEsl0e6EoP5T934dsSZ0w++fKNYN nMCLV6t/0cC/YiPDmHYPwMJEVM9UYbv7z5vuHRX2kC4Tm7ERU3ulhUYN+QRyr4D6+NcM O0PA== X-Gm-Message-State: AOJu0YxZnxmcqgVqdb/t+CYrPUyXB5wBx9tzw3XqDoTydm8xhM3oeep+ 4Y1YJ7qpjIwJJxm7XqUh587Jxmq/uv+K36nMThNeUUVLN3d4ZtJpTUFinPpKGOPWoaBMw9il2sm F X-Received: by 2002:a05:6000:186f:b0:371:8eb3:603a with SMTP id ffacd0b85a97d-37d0e77a468mr12517212f8f.27.1728406030292; Tue, 08 Oct 2024 09:47:10 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d32ea1d98sm1490936f8f.68.2024.10.08.09.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:47:10 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Stefan Weil Subject: [PATCH v2 1/4] block/gluster: Use g_autofree for string in qemu_gluster_parse_json() Date: Tue, 8 Oct 2024 17:47:05 +0100 Message-Id: <20241008164708.2966400-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008164708.2966400-1-peter.maydell@linaro.org> References: <20241008164708.2966400-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In the loop in qemu_gluster_parse_json() we do: char *str = NULL; for(...) { str = g_strdup_printf(...); ... if (various errors) { goto out; } ... g_free(str); str = NULL; } return 0; out: various cleanups; g_free(str); ... return -errno; Coverity correctly complains that the assignment "str = NULL" at the end of the loop is unnecessary, because we will either go back to the top of the loop and overwrite it, or else we will exit the loop and then exit the function without ever reading str again. The assignment is there as defensive coding to ensure that str is only non-NULL if it's a live allocation, so this is intentional. We can make Coverity happier and simplify the code here by using g_autofree, since we never need 'str' outside the loop. Resolves: Coverity CID 1527385 Signed-off-by: Peter Maydell Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- v1->v2: wrap overlong line --- block/gluster.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index f03d05251ef..e9c038042b3 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -514,7 +514,6 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, SocketAddressList **tail; QDict *backing_options = NULL; Error *local_err = NULL; - char *str = NULL; const char *ptr; int i, type, num_servers; @@ -547,7 +546,8 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, tail = &gconf->server; for (i = 0; i < num_servers; i++) { - str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i); + g_autofree char *str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", + i); qdict_extract_subqdict(options, &backing_options, str); /* create opts info from runtime_type_opts list */ @@ -658,8 +658,6 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf, qobject_unref(backing_options); backing_options = NULL; - g_free(str); - str = NULL; } return 0; @@ -668,7 +666,6 @@ out: error_propagate(errp, local_err); qapi_free_SocketAddress(gsconf); qemu_opts_del(opts); - g_free(str); qobject_unref(backing_options); errno = EINVAL; return -errno; From patchwork Tue Oct 8 16:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 833583 Delivered-To: patch@linaro.org Received: by 2002:adf:a1d9:0:b0:367:895a:4699 with SMTP id v25csp395226wrv; Tue, 8 Oct 2024 09:48:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXWBxTkw10BTdjjKVRztV11NVfpDMsnoP+X5ehKdKGSdON9atti+j2NNk/QjUCIKtc+iLXeZw==@linaro.org X-Google-Smtp-Source: AGHT+IHnl4RipXMsKFT0TkaDbwlV5Po+XGZC3jdAglFMCS1ZWYsOCHllCSlsoA7R0jQXLThP5nkQ X-Received: by 2002:a05:620a:444e:b0:7a9:bf9f:5cd5 with SMTP id af79cd13be357-7ae6f4a65e2mr2270113185a.55.1728406111047; Tue, 08 Oct 2024 09:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728406111; cv=none; d=google.com; s=arc-20240605; b=azZ3a2djqOug0DQHcWh999asFwtb95wgmRVPius60OQdAsUq1rHDIGEzeX4LvcPm6x nsGEdDCcVrZsNvtvfsAn6MUblqoYrVhEQK0gblFmSAHJisQThiKkvGuelR5TVczwlVGL gLJyyF9v8q+TL9TzNy81Ubq+rdKo2FWgFitSDbWF51X080l4/a9s/GYxdFeJPI2L672o 72wIAshX6i5Nh0GtYnxLfrUmJOb477GTFxdgA/pFnGoSbUqIEKtLyHWPhLFkGzvHGVh1 u1Y7jMiVeDJXxLVnX6UyafUO21uLqy7Jprlh1noIpRguDv1RqClrRfQ+NusXygoM7sfk ZUJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sPS8T9HM0r2iLvg9UzHQYZkqDBzvdQAydM+d7oCx2Rc=; fh=GeYAnZnQ/hHVwF5xM/bbpAEr03LDLLn0NlNLYifVRZ0=; b=ACpG2p9CPwSAaPaMw7mkmezopg/zdUrfUjzGCzaDDFyp79YtVZCxpFp9PMMpjlVScX mdQ+21SjBSwvPTyxsnJqzj6X3jHUbdcOTkobk34X1C73WH1BiNCET4m7wCByb5OoBgp8 DusuQzKU9mbZgpG/hFtpt1Pgtq1z8NLdyr/8Tg/H6ZDPg1kvvAv+77HZmbpjpridNfxD p3k7QyfUBmFo9nrKXIFXiLF6aeIfOBg7OBinyvyxyWuTVz/4q8OwI/sZSlYZthivvTMe jo+lMgCzdZUZlvOySD+MAkLxxiTGZUzsVmC7UMeEN25sQajYD8o15F+20SlqGBMCMTT8 lICg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DW6poaPa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7afcd86201asi100535385a.550.2024.10.08.09.48.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Oct 2024 09:48:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DW6poaPa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syDMi-0003Bz-FM; Tue, 08 Oct 2024 12:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syDMg-0003A5-A7 for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:14 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syDMe-00038b-JS for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:14 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-37ccebd7f0dso3856820f8f.1 for ; Tue, 08 Oct 2024 09:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728406031; x=1729010831; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sPS8T9HM0r2iLvg9UzHQYZkqDBzvdQAydM+d7oCx2Rc=; b=DW6poaPawP9XGfEdw+yWlU4JdonBavdD+V32lvJfv1hdzj3zZU99I1Wqshey7BwNE6 7jCuUL599tp4G2tZjh79kVuH8QRnvql3bgVROohFQMVXy2V95T9eEjWLpNRxq7zTiHTd EQOBdB/w4JZ/J8OE6COuzDnxW+ST1+kHa+KVlULZgH3ah8NGD1ORG1cJoWcbRYzF+Jxt BOOq8XxlA0SD/FFQlbX9IAQjWNBFNEn8X1XeHGKn3Jsz5rU3l4c2w5tR4iAT4NehPfud GMYKAjCiOtPPW6q/jHAJp/UfB1L+P7N4nYxha/UH/fafLtmVeyude5FccwJny/owm+e4 HHZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406031; x=1729010831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sPS8T9HM0r2iLvg9UzHQYZkqDBzvdQAydM+d7oCx2Rc=; b=Ruiu9o9fk7dI7VQlSeXJbCI+riTe1oanj9rTSpcW4hWGZqQwp2ExShePLL8+tNxjqL JIS7meaPWyPC49LqIU7br/SuQIWdicMdrxkb99S5AeYeWrvea9Z8EvtH2fl91Szg59rO h6oGWGZ3XlrkCI5tRXhraD9F/2QMwE86GQYneTd1NNy1+S/93SqpGMz9oOHWCW0q8Qw0 ProV3IYy2YndrA58IZDZsJB+pfKXlNtLl3DgWHCv1ZOa0GAX6Y7wX1ixUIN9DTNPmXej /802OOoNd1MW297MOKG3VtT/7asqKoJ4+cF3mT5uj4PnxIaVwKN6EdAXRVyPxx/exG1i ATiA== X-Gm-Message-State: AOJu0YytHEkKSMb3FGGXsZoSK8kfnIAib21gVP8ZD+ogrmFUd6abt/U7 mB26Dzr5Et9jetCMT0MUPuoRGBhDBj52qT+MZxeAKggaKMEY0gM9+e84XFVXo3tHFj16f1O1Tzi 2 X-Received: by 2002:adf:f005:0:b0:37d:377f:da50 with SMTP id ffacd0b85a97d-37d377fdb22mr958285f8f.35.1728406030884; Tue, 08 Oct 2024 09:47:10 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d32ea1d98sm1490936f8f.68.2024.10.08.09.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:47:10 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Stefan Weil Subject: [PATCH v2 2/4] block/ssh.c: Don't double-check that characters are hex digits Date: Tue, 8 Oct 2024 17:47:06 +0100 Message-Id: <20241008164708.2966400-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008164708.2966400-1-peter.maydell@linaro.org> References: <20241008164708.2966400-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In compare_fingerprint() we effectively check whether the characters in the fingerprint are valid hex digits twice: first we do so with qemu_isxdigit(), but then the hex2decimal() function also has a code path where it effectively detects an invalid digit and returns -1. This causes Coverity to complain because it thinks that we might use that -1 value in an expression where it would be an integer overflow. Avoid the double-check of hex digit validity by testing the return values from hex2decimal() rather than doing separate calls to qemu_isxdigit(). Since this means we now use the illegal-character return value from hex2decimal(), rewrite it from "-1" to "UINT_MAX", which has the same effect since the return type is "unsigned" but looks less confusing at the callsites when we detect it with "c0 > 0xf". Resolves: Coverity CID 1547813 Signed-off-by: Peter Maydell Reviewed-by: Kevin Wolf Reviewed-by: Richard Henderson --- v1->v2: make hex2decimal() return UINT_MAX, not -1 --- block/ssh.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 871e1d47534..9f8140bcb68 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -364,7 +364,7 @@ static unsigned hex2decimal(char ch) return 10 + (ch - 'A'); } - return -1; + return UINT_MAX; } /* Compare the binary fingerprint (hash of host key) with the @@ -376,13 +376,15 @@ static int compare_fingerprint(const unsigned char *fingerprint, size_t len, unsigned c; while (len > 0) { + unsigned c0, c1; while (*host_key_check == ':') host_key_check++; - if (!qemu_isxdigit(host_key_check[0]) || - !qemu_isxdigit(host_key_check[1])) + c0 = hex2decimal(host_key_check[0]); + c1 = hex2decimal(host_key_check[1]); + if (c0 > 0xf || c1 > 0xf) { return 1; - c = hex2decimal(host_key_check[0]) * 16 + - hex2decimal(host_key_check[1]); + } + c = c0 * 16 + c1; if (c - *fingerprint != 0) return c - *fingerprint; fingerprint++; From patchwork Tue Oct 8 16:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 833581 Delivered-To: patch@linaro.org Received: by 2002:adf:a1d9:0:b0:367:895a:4699 with SMTP id v25csp395138wrv; Tue, 8 Oct 2024 09:48:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVWlW0WINLi9pdpQBzLkX6i/RjGqqSo47iMt+tOdrxzEIGHa0ymjsrtQokubq5YuDzBDIms+A==@linaro.org X-Google-Smtp-Source: AGHT+IE4bQEHToKmjk8Yuacfp6fOAjGQWcbhhZ6BpHhaBAcSvuWDZBKGwCYwlNMYN3K++qYhK99W X-Received: by 2002:a05:620a:4694:b0:7a9:be54:4b00 with SMTP id af79cd13be357-7ae6f454397mr2329011685a.35.1728406096816; Tue, 08 Oct 2024 09:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728406096; cv=none; d=google.com; s=arc-20240605; b=VGxomPi+hRujBVoliItVHNeFFdezV3SMjtW3aAzGhuz/vDhgk+X1WezVN951vSPaF8 Ssw2jsCPxGBkT4g30ngaR7lM6Ux6SPiGzHVny0J9NNw7cZIuhbRGkkouenVYmfL0xV+P A2oD4a714qRlXTSswopMIszI5oHDOzocWshDlx+k+JkhakpwFQ+cQQbuDwa0XDxqugYZ HtQ7TMAU4PJLhNSGjBBVpAMhlPQ03Xj0NFxW+caakWF/HA6x01tj8K6ugF7ftlS5kpb0 Z7/cGI6QALk9aIdqxaN5QgwN2kybQIA6F5i4i+mHvUtumfTe68siArZQjP0ZOh5AACmW xAhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MFPIz1m97xBQWFJEuvJDqUyJljE1qr1cdlwIzcHgEvs=; fh=GeYAnZnQ/hHVwF5xM/bbpAEr03LDLLn0NlNLYifVRZ0=; b=ksw6V2MSU1GkoqlZQjqUSXOu0swpb24eivx9zjg+HZ4WjjgCDtVaZmVfywQz3bQ7Xg 0gDEd2T+wGlkAM/dADK+eWgSvMASGopI2/a05zqgYG8mow2RpM7VY1jpprNnQK54ykbL mG1OrdEgdMW9LZUdnnEvhb0bX4FjLBBJLu2k5+DPZ0kXIWyPekA/DIlksqFTdxm01dhF TbfNU4DtaaJ59Xx5kI+8gHJ7PKja19BaiZcWVj9eGtN/VDqxqqnWNYHxBui1M9x8H2I6 NYIejUi1x2Pa6fbXt+pikGC7hc8DpOtUbdwQFFgpUbK5HmzEtjYChYEj84xEId25wOJ9 eIVw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sEqfNWi6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7afcb59289asi117256085a.275.2024.10.08.09.48.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Oct 2024 09:48:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sEqfNWi6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syDMi-0003C4-QX; Tue, 08 Oct 2024 12:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syDMh-0003Ax-Bx for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syDMf-00038n-AP for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37d375ddfc0so358477f8f.2 for ; Tue, 08 Oct 2024 09:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728406031; x=1729010831; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MFPIz1m97xBQWFJEuvJDqUyJljE1qr1cdlwIzcHgEvs=; b=sEqfNWi6N1n+f3qhJCXyIZIxR83rm2K1cInBk0JTFsHpRvfHxff7rWZqOBz4kRu0tZ 4xjT+kzqgVAZfOs1zWtf+zvekgaCFugyX/wagoLrVV3+Gs+QyP1/QqL3vABc7ok66MMB Is/czDiCjzr3AmGFrO9DLFo8W5dylu/iyc3+XDwpJ61P92S/85cH/qwINeM7pkeKwBGU beDRA2iBXFASsgUwBTUimcJ8wKW9ZX2tNJ3oE89KhblyO2/RLmKmNJf/Sj/je2KNMa+8 VQe8+BSU8he4Wn8irkHAVSEnMpw43TN7MNESeeRvIETwMiKf9KZN8b3zAMc4L1EXvsVh cBkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406031; x=1729010831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFPIz1m97xBQWFJEuvJDqUyJljE1qr1cdlwIzcHgEvs=; b=Ov31Iyo/Ho0P0RNuUfWAMbhGJcJFFMHGnJbPro4JLGZ3bizhEMU1F9hdtFl6Rsi3J3 g8vPNEaMWfX8s2EgA9KUKG8jKRNuH9z/gcLKFBNSrx0FTH3sSZpxnhN/RcpWWDaZi/Fk MuywxP3xF03TvnV8eSq1mdWTcYQaSGIxyopGL/hi/94ObMc2KF6N6q82t2zG780gjNu9 vtcEulPGjYjhfHRCVkjv1EH76WmFef7vDobriq7LZkaZloswWdcEF+wwgIoHKXxmmM2X rTEQzCseXO6zPtMMlpuGE/glxdT7XUMdaB8v6p9Ooi0i1/qZ0NwwlS3H6eEIRXcYjAkJ cvDQ== X-Gm-Message-State: AOJu0Yzefs+nV8v7ZEwLINccLBsYhmSPIX+dlbhJKB6eE7lyYkUnDqn+ 6BRsHy48lCtHkua0gsAFTWLq9sFPiNr/yTOSlKj/8zmfWu59+f37dthGcq3v3jnDCiOyKpe39m3 N X-Received: by 2002:a5d:608b:0:b0:37c:c628:51bc with SMTP id ffacd0b85a97d-37d0eaea1a3mr8961595f8f.57.1728406031541; Tue, 08 Oct 2024 09:47:11 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d32ea1d98sm1490936f8f.68.2024.10.08.09.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:47:11 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Stefan Weil Subject: [PATCH v2 3/4] tests/qemu-iotests/211.out: Update to expect MapEntry 'compressed' field Date: Tue, 8 Oct 2024 17:47:07 +0100 Message-Id: <20241008164708.2966400-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008164708.2966400-1-peter.maydell@linaro.org> References: <20241008164708.2966400-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In commit 52b10c9c0c68e90f in 2023 the QAPI MapEntry struct was updated to add a 'compressed' field. That commit updated a number of iotest expected-output files, but missed 211, which is vdi specific. The result is that ./check -vdi and more specifically ./check -vdi 211 fails because the expected and actual output don't match. Update the reference output. Cc: qemu-stable@nongnu.org Fixes: 52b10c9c0c68e90f ("qemu-img: map: report compressed data blocks") Signed-off-by: Peter Maydell --- tests/qemu-iotests/211.out | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/211.out b/tests/qemu-iotests/211.out index f02c75409ca..ff9f9a6913a 100644 --- a/tests/qemu-iotests/211.out +++ b/tests/qemu-iotests/211.out @@ -17,7 +17,7 @@ file format: IMGFMT virtual size: 128 MiB (134217728 bytes) cluster_size: 1048576 -[{"data": false, "depth": 0, "length": 134217728, "present": true, "start": 0, "zero": true}] +[{"compressed": false, "data": false, "depth": 0, "length": 134217728, "present": true, "start": 0, "zero": true}] === Successful image creation (explicit defaults) === {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "file", "filename": "TEST_DIR/PID-t.vdi", "size": 0}}} @@ -35,7 +35,7 @@ file format: IMGFMT virtual size: 64 MiB (67108864 bytes) cluster_size: 1048576 -[{"data": false, "depth": 0, "length": 67108864, "present": true, "start": 0, "zero": true}] +[{"compressed": false, "data": false, "depth": 0, "length": 67108864, "present": true, "start": 0, "zero": true}] === Successful image creation (with non-default options) === {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "file", "filename": "TEST_DIR/PID-t.vdi", "size": 0}}} @@ -53,7 +53,7 @@ file format: IMGFMT virtual size: 32 MiB (33554432 bytes) cluster_size: 1048576 -[{"data": true, "depth": 0, "length": 3072, "offset": 1024, "present": true, "start": 0, "zero": false}, {"data": true, "depth": 0, "length": 33551360, "offset": 4096, "present": true, "start": 3072, "zero": true}] +[{"compressed": false, "data": true, "depth": 0, "length": 3072, "offset": 1024, "present": true, "start": 0, "zero": false}, {"compressed": false, "data": true, "depth": 0, "length": 33551360, "offset": 4096, "present": true, "start": 3072, "zero": true}] === Invalid BlockdevRef === {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": {"driver": "vdi", "file": "this doesn't exist", "size": 33554432}}} From patchwork Tue Oct 8 16:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 833582 Delivered-To: patch@linaro.org Received: by 2002:adf:a1d9:0:b0:367:895a:4699 with SMTP id v25csp395221wrv; Tue, 8 Oct 2024 09:48:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVK3tZbzOzCJg17l1rMTT/JMEWZKTjpllaUSfJQ9Y8tCQXk2XfCnI878V6I5RDt8U6qR75/rA==@linaro.org X-Google-Smtp-Source: AGHT+IEbzVzCYzfQ8PGkja3hRiqNDKwb27KikfPP8dDAYxygjJO3QEJVqwij2WqIQgwSUUxhxrRe X-Received: by 2002:a05:622a:528c:b0:45f:874:e488 with SMTP id d75a77b69052e-45f0874ec21mr9689301cf.59.1728406110514; Tue, 08 Oct 2024 09:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728406110; cv=none; d=google.com; s=arc-20240605; b=RF4IIUvOdD68rCDTlb98nIymX+ED8O3EJwTtuniA0W1EXLmOL5XAwbkhtV5GB4QACJ ebv3QcKkv/H/M9btHtIz2JkSTu7J7G/zv6ZP/TcJx9QaY6snzmugGwqUL4xLGeQPMis8 5do448JwGQryj++sl1rRy3PuTpx0hNdtYNRhBK62PZ3ZZ6lOLpHins8bV9jJgyryPrQ5 iPq8VPdSyJDZS9Pq8kItYe8JOaZhXEiGWXdKLiglGQFjW7Rc0vHz3gkUticCghyVQxwG C0yQ7HIP86AqoO8F4KRI14qwsTgInhQ91IFzB0zXp6wKqo4X3Elec19Rxu5n6NEZlBwe a89w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; fh=GeYAnZnQ/hHVwF5xM/bbpAEr03LDLLn0NlNLYifVRZ0=; b=H4EGRVdgjIZC6OXxHVVhMK6yZ/9G+paQmkjKMCYCwru9R4rv3uzZ90cUaS6kQmNAhU OGCaTESK9Z6eV28IPGi7LNiewAIdKyjFcy85Al8R9p4uDei5WnBage+OGavEkatVyBJb 3mpxXLD2xr2wR6wOxaC8VxKK34UDBQOe/+pGgLAnKOM/EN99xW3sjn7A9abPT9H8wwai 96VCHxSgLog2mz/O9hGGmXRo7WV93JE+7VTSN7nmr7mCl1SXqGvehd+jy9avXbG2zsAl HQRwi35WZNPhUlPS5u7r6h5CQE7PwxDTXbKWh+SLfFuwU1HSi+6gXD7wmyztsuVFszTx EdJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YNQGE7Zb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45f01d28d74si12386741cf.438.2024.10.08.09.48.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Oct 2024 09:48:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YNQGE7Zb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1syDMi-0003C3-NL; Tue, 08 Oct 2024 12:47:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1syDMh-0003B2-HQ for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1syDMf-000390-Js for qemu-devel@nongnu.org; Tue, 08 Oct 2024 12:47:15 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-37d1eda8c7cso1638444f8f.3 for ; Tue, 08 Oct 2024 09:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1728406032; x=1729010832; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; b=YNQGE7Zbz67MiS/QVL2ytaCx7GyldhJe9dMQ4s+pcCAokwb4hgUGFzHC4c58bnDn0J JZ+vGUfjKr4quuIP7F7QGs0JBliSRSZRhNS4g2KVb2nLLVgt3A2mo+Va1hkgvZREABXU TqChSGruzc1mZcGwektoSC7tETQqX8uUVce7Mi33RIhbNnWadEqZVjj1BJoEAAeUWuIS VNwjQaWmvBPbimVXtPUDFtgp8sfNGE+RY8JtIkzCwB7AgWncV6dbn/YDuteZSPBBA7i6 h0gh/PvrUShHuwSBM6blqeQrstS8iH0mXk/grisn0z0QmuFyiJQ5htC5RAW91G4Qelxb DSsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728406032; x=1729010832; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EY6w9wvwlC/cLOufBH+NAUI4yIvgWqgEs7u9iu6gMAw=; b=WKiIFgJsAIRA2q2oktAMYkQTSqAOEQKhc5q7GCWMv3oHD+u1b03ujGzvjZAfzMCjrv oDZJwQ44tkev9Sd1sd/ICDeFoqAml9Vcvf9c61pzaZs3JpYp/FLEOnHMooM0FFoIv4go MAPg2Ki3RAxOM8pQXKZp1kGWCDCjgAkEpf77b0UcdUJQF0W9llOkdYBrt7tzx9xmUAH0 s1QMW4bnb+Zwu+MtGZJklIlPNHYgDFeYUb5vvXHwP11Zc0woj2AlJkj1rV5lV2hiT+k1 9nILD7Nxht5buOGym24WyNW15jf33sQ5azmzoV5jHHnWQCruZxKshIxKC7Tff6616Mys 5LuA== X-Gm-Message-State: AOJu0YzyF4EBorzAEBPDkz0xnKwmFvxV5SfKxaU+K9aogA9DhCO1Kd/G LxcHSJbBdSZY0DAkXDp5Miji7veC2GnmauovZof/JQ4eH0cBgi4xDg2ORC0NZU6QhQcTc/LiEBK O X-Received: by 2002:a5d:5c87:0:b0:37d:2e78:8875 with SMTP id ffacd0b85a97d-37d2e78a2a4mr1470394f8f.56.1728406032104; Tue, 08 Oct 2024 09:47:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37d32ea1d98sm1490936f8f.68.2024.10.08.09.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 09:47:11 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Stefan Weil Subject: [PATCH v2 4/4] block/vdi.c: Make SECTOR_SIZE constant 64-bits Date: Tue, 8 Oct 2024 17:47:08 +0100 Message-Id: <20241008164708.2966400-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241008164708.2966400-1-peter.maydell@linaro.org> References: <20241008164708.2966400-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Make the VDI SECTOR_SIZE define be a 64-bit constant; this matches how we define BDRV_SECTOR_SIZE. The benefit is that it means that we don't need to carefully cast to 64-bits when doing operations like "n_sectors * SECTOR_SIZE" to avoid doing a 32x32->32 multiply, which might overflow, and which Coverity and other static analysers tend to warn about. The specific potential overflow Coverity is highlighting is the one at the end of vdi_co_pwritev() where we write out n_sectors sectors to the block map. This is very unlikely to actually overflow, since the block map has 4 bytes per block and the maximum number of blocks in the image must fit into a 32-bit integer. So this commit is not fixing a real-world bug. An inspection of all the places currently using SECTOR_SIZE in the file shows none which care about the change in its type, except for one call to error_setg() which needs the format string adjusting. Resolves: Coverity CID 1508076 Suggested-by: Kevin Wolf --- v1->v2: v1 just added the (uint64_t) cast for the specific issue that Coverity was warning about; v2 is entirely different and takes the approach Kevin suggested in review on v1. --- block/vdi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 149e15c8314..26f7638f1fc 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -87,7 +87,7 @@ /* Command line option for static images. */ #define BLOCK_OPT_STATIC "static" -#define SECTOR_SIZE 512 +#define SECTOR_SIZE 512ULL #define DEFAULT_CLUSTER_SIZE 1048576 /* Note: can't use 1 * MiB, because it's passed to stringify() */ @@ -442,7 +442,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } else if (header.sector_size != SECTOR_SIZE) { error_setg(errp, "unsupported VDI image (sector size %" PRIu32 - " is not %u)", header.sector_size, SECTOR_SIZE); + " is not %llu)", header.sector_size, SECTOR_SIZE); ret = -ENOTSUP; goto fail; } else if (header.block_size != DEFAULT_CLUSTER_SIZE) {