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: 1967127 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Wl1onWjw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WYvp66wM8z1yYq for ; Thu, 1 Aug 2024 00:37:50 +1000 (AEST) 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-Google-Smtp-Source: AGHT+IF9r4V6T2a2m+mgsn3GI7Y2U5gf/aG2t4Zry+80JI0bMJ9IWysDmCtxx6a+j5H0q0Gi3BY1aA== 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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++;