From patchwork Wed Jul 31 14:36:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 815652 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp773345wrs; Wed, 31 Jul 2024 07:37:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW0uPWzGScJtXlaXJ5mIAZ+WVNbhEnEuW93WTTLumUy+bECEl1O6MsFqJablXjgNbhT+hoF/PoITibiDX/TuPMc X-Google-Smtp-Source: AGHT+IGjcH2tamjBJNOJ22DHV7CvTqJLHN5hiXTHnRypGWEbR5KSSTNVXblH5DPAlyN6KBwYV3Dy X-Received: by 2002:a05:6808:1593:b0:3db:1ca7:3618 with SMTP id 5614622812f47-3db239cfebcmr16550617b6e.23.1722436669692; Wed, 31 Jul 2024 07:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722436669; cv=none; d=google.com; s=arc-20160816; b=YHcdfEon6QFiT2iYNQ3SK8KjlxvKkJOOs8ka+LhwsLQzYdYbJTrrkH5JpBe9LnIZSI qbQFeo+YQTLMlMbE75338U421zRkmLfOSzRqPqlzwY8N9eIDQoqGRKBdy0XSmBqR8pNk 5BamUosIXJPXcrjukK4hMq5xFUDjpTlLBwPyvQ664xOYkxI/dlhU21K0Hjifkp73J3do vttURVnapRWRhS/XS8DqluwgxFsldQVC/ehaUF0+B2RGoKvbdFAnTg/fhTT3VCVzNUf0 igzaQa32zyf1vJrN4qDjfa5n2FbLvwcEmq8Stj+wrv8Jmv1qJAwGSPgIgNb/pD5TcwfL UnTw== 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=6N+m3/t8IvmE5Sgkmkq6gGUNm/dDeZpi/vHzdYBag3E=; fh=5quBhmNe3tsEAdid5ZAgwbHv9gtP/oew6yvM24yBrbo=; b=qc4LC4F0bArEgRDP2sFnDXhmDivSbHiwqpn9ZumAA+hiQ2N1LnmKvQ/znbeY86yySn wEyD1lCuRslbyqWze+YBkWaCD2X3H6+7KTUzg0DQ45VjzgoUmb/W/zfllNKyDyVP5nEU BcDsqSBsJK8XixNHbAwumpSW4a0Il781kZiDRi+Fjhd10Hg1R93kyvu6/Pkd4cLc+e9K 3AfMR4Dn0rB9Xjijyo9/DOIx0YcTJoH5u3opUbOBRTUjUd9GWx4Tq/D/hyZN/yVjcUTg /Qa1RzaJRdlZ+2zUat7uJS2GnQnyuF5y38wwOqZXo5cq+b6shssxlZtVuR6L92sErTWQ 4oEg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wl1onWjw; 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-44fe840a0c4si150527601cf.416.2024.07.31.07.37.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2024 07:37:49 -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=Wl1onWjw; 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 1sZARP-0004nr-Oo; Wed, 31 Jul 2024 10:36:35 -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 1sZARJ-0004Vc-17 for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:29 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZARE-0002ek-Ki for qemu-devel@nongnu.org; Wed, 31 Jul 2024 10:36:27 -0400 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2ef2cb7d562so75761411fa.3 for ; Wed, 31 Jul 2024 07:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722436583; x=1723041383; 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=6N+m3/t8IvmE5Sgkmkq6gGUNm/dDeZpi/vHzdYBag3E=; b=Wl1onWjwY1bhrprcnf3qQgIF5Wr4/hlPrBlS09soj9EG5HOgZBZJ15024cIlmuSAK5 zb1qy/v/iIhgjdgiIKJ6IPu9k6VzLfLa9Nq/lmpzdOHwtP6fbzFop/sQfHZiyIu14bjm uZ9WQ3zeTtQ7xibONY+ii5s2mvHk9mLPUBZ/pTYPJsiLsAcEhnIRb25ctuDvTbXEhU2u ArZ2C3AaSOng9fQHhMzPSXOtv9h67c3KGB/yBEDoQI8BxsIIk1tVPdIfAcElRPWbUja/ 4NrLd/SEB/83CTpOoozwc0ZM2icRQcv+nq9AnkIB2JSLhB+QfkFptRe41j1ITuKv4SJO hW7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722436583; x=1723041383; 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=6N+m3/t8IvmE5Sgkmkq6gGUNm/dDeZpi/vHzdYBag3E=; b=SlxxCpoYcBLikr+lFMq+EWk3ArDQ9V5r+q1Fb9iaQa3Eh2aqVUuT9Pu+AGv79ByByC /VciCaLozbcuVBfAzMprkH1z9GSkqnja6HyCGPnZVcxTy0tCSbNx4aZJ5PC0dtJHhO+t 3vpp/SiKo3IBMfWkqrdHPv/K1KU2aRcQcZswsb9+oKKAg38apB9I9GC3CjhSzXIXCaEJ pM0dQzwGdu4jRSLGY3Ax14MggvLUDg48Aduc6WjC3L1biJD/yIi2MSaNXfTfjQi0N4QI ENqYwu6sqRVmrl/MbDdii5efUR3tkC9U2ZNYBdKXooCARryffgjK/Ik7cEWwcPDtFf3y Yrqw== X-Gm-Message-State: AOJu0Yxid0YtCvroYZnbERCVOGlMwDxudkRVEeTgVSWh7dEU+STtD5Pl NbcaMEQp4eB2Ig56P3qriBVAjztLuc9Z5KhoLMI8WjDFSWDCx7jKzZGLGSrRdyWFyNPwgww8ADH N X-Received: by 2002:a2e:9dc6:0:b0:2ef:2b06:b686 with SMTP id 38308e7fff4ca-2f12ecd2d3fmr109026131fa.17.1722436583009; Wed, 31 Jul 2024 07:36:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 07:36:22 -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 7/7] block/ssh.c: Don't double-check that characters are hex digits Date: Wed, 31 Jul 2024 15:36:17 +0100 Message-Id: <20240731143617.3391947-8-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::22e; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x22e.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 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(). Signed-off-by: Peter Maydell Reviewed-by: Kevin Wolf --- Could alternatively have put a g_assert_non_reached() in hex2decimal(), but this seemed better to me. --- block/ssh.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 27d582e0e3d..510dd208aba 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -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++;