From patchwork Wed Jul 31 14:36:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 815655 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp773411wrs; Wed, 31 Jul 2024 07:38:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW4bn/ei9ardtMfY86TNnuq3CIjfgBVk+W2YOAigQzt7JnJyvgS6xyK3y/OdZtk0xvd3RS66mojxc5XV7O3r5xo X-Google-Smtp-Source: AGHT+IHUIjPuRBHWE31R1nsd/4UT+Z3a3uRgrH2hjzAXXXFp4yadjFPWN2c18uKkDWHzdWU3EvH6 X-Received: by 2002:a05:6214:ac4:b0:6b5:4338:e029 with SMTP id 6a1803df08f44-6bb55a17e8dmr205908636d6.28.1722436680842; Wed, 31 Jul 2024 07:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722436680; cv=none; d=google.com; s=arc-20160816; b=n5uI7Fn+hx2jVAdA6lFIhI9w+tkYrnAwN7fvhnRL76xXPI3VgBKQThm0+pm6vg9m6t xI6kXo+emL6LaZVg/bMAOSYiYvL98yQnJgeNGAyquw61EsH0rQl6ooLkc9QlB7K8cg3a 1Zrs1eagH6PMv7m0aHxJvVxayevU+/VusB9CkOjhMMOdjCsN4rXMcAsyzYp0PXDrK0lP DY4M8kaVR3gAbTO842B4VtTFxyHXvEM2UqN3rtMS2CzpL+KHpH5bnuetvhm6SSefZq1o XjoqqR49+nTlXssZN2J5mHdm4TI50DqDcK6UR6D1qP2IrZjatVMFFhq8B8KYxQxO6BDU 5ftw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=MAd46eTldG2I+2ED6a/rVkcfbA6YevMDXfrDk/LBM/Q=; fh=5quBhmNe3tsEAdid5ZAgwbHv9gtP/oew6yvM24yBrbo=; b=vRxBWFs3Ght5aamSElHWhu1r2+RUDDsRcBY3AMVvByAAj5x/xcCOhCn7J1RzUPjMh4 E4XGR/vuR8MCCrzsdlaeSmzUfEwDseIdrGePUV832s+fYtD726HSSpItFgnGPtKcMinM qs9Mh4ujSKh5K9hOaSCe0/Pt+JUbYLAcP87pFuiJgMorONFVAvvY+bR+AqbQlS8WmYr7 D5wQqMKpXVjhnmE+ZkbbHFLa6meKZ1LnBVM0tgX3Lb+eQ7ilGOn6lXcw86C9hMjOJllB 0Up6Z9+qjTCJ1UOTtpkvw/B49BlAfJUuqfMUDhdMjCgL/QhWFfDy1WkbfB0dhdiKaVqO Hm+A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R8kL5rlZ; 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-6bb3faa99a2si158884666d6.319.2024.07.31.07.38.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2024 07:38:00 -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=R8kL5rlZ; 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 1sZARN-0004kj-I9; Wed, 31 Jul 2024 10:36:33 -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 1sZARH-0004V3-Sl for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:29 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZARD-0002eN-OD for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:26 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4281f00e70cso26130155e9.1 for ; Wed, 31 Jul 2024 07:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722436582; x=1723041382; 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=MAd46eTldG2I+2ED6a/rVkcfbA6YevMDXfrDk/LBM/Q=; b=R8kL5rlZThLIGA8FZC7y/fcakAuzaOdaxHQoVW6yhlnmNmr5Kkg9TULROnItIo8tDs syiDj3S1+0/sGJdER4TCxKAv2e+wev+Kip9yEUroMk3667fZX6V3hcz91VZtLUZ2Js+V bPo5Pq4ynjGUmy6QrvNLXa3FXI/+XCXOgNgHkzAdFy6mENXFfLJLK09mmN9+qPWvNESE 66ZfdaJFGWL18Z7KCpWOgCtuw4FQIHF5nweUzZ8jCX3BaCuzZ/SjIRcSF9Lp4hxkXOav P+9dGIXEXVbSLA+aCAiuZThn94P+9uNkoX7/+gjGRdwxNH9+mlOyMWmaHlAR296KSsHa LWew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722436582; x=1723041382; 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=MAd46eTldG2I+2ED6a/rVkcfbA6YevMDXfrDk/LBM/Q=; b=h5oMUuVUJ6f6r0YZuZgeM9lLMAQGistYQLKzkdw3nB/qizRI3EUNUkb3dXNIfx9yg/ Sct+ofZjfWQ0tvFPt+uiilOOApz/Nq/dp+s2bjiLe4fTpw5ppLHm3Ypw1oGwohMO5SZf Fkwg1CMRH6ZEqSafRIECHoO1irBHaHN5Fe+fudAiTTre4dlCao850QXmwz/a9ot0tGgb A/rXPgE7rtKQ3dP4X2rIluq9UCckiiItwL+oIBczhaVuLyJziX2SiwEWGE6oUOU4U/1O +2P78t7ChZlmVh6kfn78yCMegvAn6CSZDWofomJjNH6KwVYKu2ts50+Tuz1gyvPt4/as hF5Q== X-Gm-Message-State: AOJu0Yx6Vpo9fabvl0ZXNE7KjuJ3yKsD3ZQWKKUOvyIn4jmS31UqfNbf 27XIsJN0hj2VN0xI1s60Jv524aEfXxrg7WEi8eQ1osg90ZdiT4cf25w4iiQ2AzzwqEa7D48OBmH 4 X-Received: by 2002:a05:600c:4c1a:b0:428:10e3:a000 with SMTP id 5b1f17b1804b1-42811dfe3f3mr77300845e9.37.1722436581874; Wed, 31 Jul 2024 07:36:21 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4282b89a86dsm23976025e9.1.2024.07.31.07.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 07:36:21 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , John Snow , Stefan Weil , "Richard W.M. Jones" , Hanna Reitz , Kevin Wolf , qemu-block@nongnu.org Subject: [PATCH 5/7] hw/block/fdc-isa: Assert that isa_fdc_get_drive_max_chs() found something Date: Wed, 31 Jul 2024 15:36:15 +0100 Message-Id: <20240731143617.3391947-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240731143617.3391947-1-peter.maydell@linaro.org> References: <20240731143617.3391947-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.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 Coverity complains about an overflow in isa_fdc_get_drive_max_chs() that can happen if the loop over fd_formats never finds a match, because we initialize *maxc to 0 and then at the end of the function decrement it. This can't ever actually happen because fd_formats has at least one entry for each FloppyDriveType, so we must at least once find a match and update *maxc, *maxh and *maxs. Assert that we did find a match, which should keep Coverity happy and will also detect possible bugs in the data in fd_formats. Resolves: Coverity CID 1547663 Signed-off-by: Peter Maydell Reviewed-by: Markus Armbruster Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daudé --- hw/block/fdc-isa.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/block/fdc-isa.c b/hw/block/fdc-isa.c index e43dc532af8..796835f57b3 100644 --- a/hw/block/fdc-isa.c +++ b/hw/block/fdc-isa.c @@ -147,6 +147,8 @@ static void isa_fdc_get_drive_max_chs(FloppyDriveType type, uint8_t *maxc, *maxs = fdf->last_sect; } } + /* fd_formats must contain at least one entry per FloppyDriveType */ + assert(*maxc); (*maxc)--; }