From patchwork Tue Mar 12 18:38:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 13590502 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19054C54E5D for ; Tue, 12 Mar 2024 18:39:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71G-0003aT-R7; Tue, 12 Mar 2024 14:38:34 -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 1rk711-0003NE-R5 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:20 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70w-0000c9-I0 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:19 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-41342849a15so1965085e9.3 for ; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268692; x=1710873492; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=YLwrLK6pe4v4As4FiQrlSek3puRi+quH0IgezmVNfJ4=; b=HcRIvthYq4A0mQf2YXObfenS22poAr8WP07lH/HI+PHs/eVo/EX45zagQmSu/zky5l KvJdCXezzTIsYmiqRYo2HJhVF6rYZSRi8+ZCiw/UsEKG6SIFHCHN9w6j8gtS62Q7uTt8 PoT6s9SL34EJsFerAqZPN3bPbEQGm/MMKuShqMRAGHTv4XlDQu6fMAU7RgSQJCbMqiC0 OOep0it2IvzMPehED/Q+z8KCX8LP1DVvkMfUOjnu3SpGByTObeX0tzY+6EQeD6zIQuVg WFGHv5Y+beVPzSv9o2NKnVfRddTyWerqSN1XW8aGNA6/dR6zJwP/K7+L6iu6bUNCRuL0 7nUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268692; x=1710873492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YLwrLK6pe4v4As4FiQrlSek3puRi+quH0IgezmVNfJ4=; b=X7EPUvmmbOUmwVolrSlsHKlFd35sYqnhJk6qFnSXZm6H7qBsMObzmg5F053BRPZMSX a+mZyB8xE+tmU0uTPctpfwkv3RbHsxJq53X1n7Z3YoY3chTd/+yM8vcZ8FZxDTesNCLD SRIcu2laqrPjS99DVeJUngCS97wt8zRN1c6f3Fipd8OgU7lwhjGSozQGbvPB0hnE1j/Q MpQD+tuHUx3GEpGT4PBzDxQHoK+YeHX5ZAQUess2GwDTdg40BDKxoH+TooBiNCoeZ5xi ANxgtIHJAjEMxI+LcMABt90Y3O53CpaPCVxagZqRMSZLME0GmnTVeANs+4jmlkgcNMEo GibQ== X-Gm-Message-State: AOJu0YyN5KcYsHorpQIVo/4HGnzPvQnyWSXonJkUcG9i1dTqojeum7VZ abYzvolSw2HpKYTxA7TYXC/EhKgWltC9MYoIX1eE9sEPSWtEEgmWlJ6Ze8XsGMk7+Z68uTv9XwZ f X-Google-Smtp-Source: AGHT+IExvX9etNjG2m9zYy8K6UGpWBI2GcYWr81eEb9/KCcQ75QINY31KfIJcjROtSG7maBP2G1IXQ== X-Received: by 2002:a05:600c:4e56:b0:413:1645:29a6 with SMTP id e22-20020a05600c4e5600b00413164529a6mr733115wmq.22.1710268691930; Tue, 12 Mar 2024 11:38:11 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:11 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 1/7] tests/qtest/npcm7xx_emc_test: Don't leak cmd_line Date: Tue, 12 Mar 2024 18:38:04 +0000 Message-Id: <20240312183810.557768-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In test_rx() and test_tx() we allocate a GString *cmd_line but never free it. This is pretty harmless in a test case, but Coverity spotted it. Resolves: Coverity CID 1507122 Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth Reviewed-by: Thomas Huth --- tests/qtest/npcm7xx_emc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c index 63f6cadb5cc..2e1a1a6d702 100644 --- a/tests/qtest/npcm7xx_emc-test.c +++ b/tests/qtest/npcm7xx_emc-test.c @@ -789,7 +789,7 @@ static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd) static void test_tx(gconstpointer test_data) { const TestData *td = test_data; - GString *cmd_line = g_string_new("-machine quanta-gsj"); + g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj"); int *test_sockets = packet_test_init(emc_module_index(td->module), cmd_line); QTestState *qts = qtest_init(cmd_line->str); @@ -814,7 +814,7 @@ static void test_tx(gconstpointer test_data) static void test_rx(gconstpointer test_data) { const TestData *td = test_data; - GString *cmd_line = g_string_new("-machine quanta-gsj"); + g_autoptr(GString) cmd_line = g_string_new("-machine quanta-gsj"); int *test_sockets = packet_test_init(emc_module_index(td->module), cmd_line); QTestState *qts = qtest_init(cmd_line->str); From patchwork Tue Mar 12 18:38:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 13590505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08620C54E5D for ; Tue, 12 Mar 2024 18:40:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71D-0003VW-0M; Tue, 12 Mar 2024 14:38:31 -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 1rk70y-0003MZ-N7 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:17 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70v-0000cB-R1 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:16 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-41329b6286bso14727745e9.0 for ; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268692; x=1710873492; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=09aQF63pPHOllcqpbcVLj8Q606SuNrCw0WJNZs+4sLY=; b=dL20NEt8U99+WpjLVmbF2fkkSD7tFmqjoeMGHuH6mTpcXSr0VZ7GZob7jK/E0ajq+E pgHi9+t0JEvNwFUBJ5YAPXW21n63uEFv2VgX8AiErBSLdMAOV0+qqsqAKqniPrjbeW+A acwZlA7iXwjlLvv0A1DZDqDzidp25/+FWGXAHo63DcRbUCU9YgUwEXsA5p6qASxeu7aQ JLGS/rqgUPSM/ZsWSkQzosoeGCzHbDcaCNXYxZsWX+G8eidZOdw0Q8nkdSrTOmN8Ge8W 1k2O2MUtvJ3ADHmUn4jYgfolLg80IJRjQNwVOwFQxljKHyLeJFsthO0sfq3wBwfoj7eS Kv9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268692; x=1710873492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=09aQF63pPHOllcqpbcVLj8Q606SuNrCw0WJNZs+4sLY=; b=DsEKRj89b2GnHfBr3C96Sycg63s2rAMyxR+Cn0nwnJvw7t/jiL3Yz2EshqvYZe9wM+ capSidjQMYsmwXLShSYpW+At+9xcT1jImj4Rd/uQw9AUz60sgqjdSSzXlew4ifnbykp0 iwwUViVi6Ibu2uk/9u/HUIsDU3pxS0HmhIWNYhEMXpBc5gGZab7FMVxHuBFujK8IaopR klTV6ktsA9W7jpJI5oGUOrW4PH7tW5AYhc6+iPE51iXxZ2S2AUDM7SAhkVkXPONpMrZ1 HDlLdaiFjLxZEndfzHLCVx0ev7kFuP6YrD/IZsRtvVC8JOR0qGeqZn2L48E5zY20iMNF RKvA== X-Gm-Message-State: AOJu0YzffBMYgnuUu3p93WRwXCl5ufa8KqA5tN5n1RHuMYm/3Ujynu09 1ae/fZPynsHxMSV0s9tH2HCnUGcwbbHr7Ou9mJ7IHydy4+gYk50nOy3DM4qdqHuIU5o0+XApxX0 b X-Google-Smtp-Source: AGHT+IFcPmXgLbxw2ogGFg5MI9T/giG3aT3005B5qv1ibPNKlJ9Q5r8VGlh+3MXoVKMbNF18A9IhOQ== X-Received: by 2002:a05:600c:548c:b0:413:271a:1e5e with SMTP id iv12-20020a05600c548c00b00413271a1e5emr691533wmb.38.1710268692473; Tue, 12 Mar 2024 11:38:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:12 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 2/7] tests/unit/socket-helpers: Don't close(-1) Date: Tue, 12 Mar 2024 18:38:05 +0000 Message-Id: <20240312183810.557768-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In socket_check_afunix_support() we call socket(PF_UNIX, SOCK_STREAM, 0) to see if it works, but we call close() on the result whether it worked or not. Only close the fd if the socket() call succeeded. Spotted by Coverity. Resolves: Coverity CID 1497481 Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth --- tests/unit/socket-helpers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/socket-helpers.c b/tests/unit/socket-helpers.c index 6de27baee2e..f3439cc4e52 100644 --- a/tests/unit/socket-helpers.c +++ b/tests/unit/socket-helpers.c @@ -160,7 +160,6 @@ void socket_check_afunix_support(bool *has_afunix) int fd; fd = socket(PF_UNIX, SOCK_STREAM, 0); - close(fd); #ifdef _WIN32 *has_afunix = (fd != (int)INVALID_SOCKET); @@ -168,5 +167,8 @@ void socket_check_afunix_support(bool *has_afunix) *has_afunix = (fd >= 0); #endif + if (*has_afunix) { + close(fd); + } return; } From patchwork Tue Mar 12 18:38: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: 13590501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E413C54E5D for ; Tue, 12 Mar 2024 18:39:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71C-0003Uy-Oe; Tue, 12 Mar 2024 14:38:30 -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 1rk712-0003Pc-6q for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:20 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70w-0000cF-JZ for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:19 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41324a16c9eso2033875e9.0 for ; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268693; x=1710873493; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=leIb44YVt2ONZNF3/nNgR8JxpEyw4LXHpjhhtBaqKe0=; b=v9dHZnYRG7+oD5nMa8uuk9IwitY1efDwuWbM5SA3lQhK7HhNONltNzbAQf3PnQjPE/ OLwk47u69wteLpQP1RREDM17Kbak1zNCNFgTtDVLGuLSaZquB8mkp/fwXRC3Mg4F/ts+ NAlp9Io5yvkUDGbtudnCJlDi0feaBPw5Dz9b25nyyv0wMqm32DW7TjYt7DoWlEM0UniY f93J1LDVxJPateL7RFswqhdhswjWxvn2YMsrHBs+nnsj+aPhHkg9v+jig4E6/aDOP5zY +myhKsz/2N2ViK63app6y6auw6vRYbl02BaWrZZYrz9JmH9TIlkhVcqoSacDAn69nH4J NQVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268693; x=1710873493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=leIb44YVt2ONZNF3/nNgR8JxpEyw4LXHpjhhtBaqKe0=; b=HvICX1pCawcgO62K8IZqoz7uExj9odJ+C6SuTgmiCMcfZ2iSyF0u3eG6CsGxhsayIz PZO+/Xsc9Nd5Moy/WnBFYfnXMBjyBxcP+3/tRLPhtRqTD7lBwqxPw2tiueI/C+UQpzbD 6fR8qmDCnXRRDVjMNj7M+3Gvid4HidFfAuaQ06zFycHa6Fw/SLHcl2oO0hp/a/yu9wIc xR5l3SmAg7r38eNXd+Y4Mmpcde0sr+sFc3Xu//046lBG8JyJKfe089njfe+nszyiGzLt CTFeb+HDcoBGncf81BO1MpA/4FaihZhhkG8xnK9wT3+udaUeBHz3DKjZ8UnqmaCilx7Q 3B5Q== X-Gm-Message-State: AOJu0Yz/DL321qG0SzpyosTB8h7xPPN4+OUxne/YgmWy6BW1MtUDllnk +xduo2YkoxShTNGWbgP3HOelZ81TeXojY1nB6ycbU6FTwSwXV+U7zX7/bgEY1WotPEx1XK6erQE + X-Google-Smtp-Source: AGHT+IFMXZxlZWD6xdAgsWjbQGHi6yO2Ush7GT29bYIqI3BHAedvH0BvRkjENbC2sTq2Mp4HqNH6Xw== X-Received: by 2002:a05:600c:45cf:b0:413:e4cf:109d with SMTP id s15-20020a05600c45cf00b00413e4cf109dmr846067wmo.1.1710268692868; Tue, 12 Mar 2024 11:38:12 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:12 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 3/7] net/af-xdp.c: Don't leak sock_fds array in net_init_af_xdp() Date: Tue, 12 Mar 2024 18:38:06 +0000 Message-Id: <20240312183810.557768-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In net_init_af_xdp() we parse the arguments and allocate a buffer of ints into sock_fds. However, although we free this in the error exit path, we don't ever free it in the successful return path. Coverity spots this leak. Switch to g_autofree so we don't need to manually free the array. Resolves: Coverity CID 1534906 Signed-off-by: Peter Maydell --- net/af-xdp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/af-xdp.c b/net/af-xdp.c index 38e600703a3..01c5fb914ec 100644 --- a/net/af-xdp.c +++ b/net/af-xdp.c @@ -446,7 +446,7 @@ int net_init_af_xdp(const Netdev *netdev, NetClientState *nc, *nc0 = NULL; unsigned int ifindex; uint32_t prog_id = 0; - int *sock_fds = NULL; + g_autofree int *sock_fds = NULL; int64_t i, queues; Error *err = NULL; AFXDPState *s; @@ -516,7 +516,6 @@ int net_init_af_xdp(const Netdev *netdev, return 0; err: - g_free(sock_fds); if (nc0) { qemu_del_net_client(nc0); } From patchwork Tue Mar 12 18:38: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: 13590508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BFD8EC54E58 for ; Tue, 12 Mar 2024 18:40:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71C-0003T6-1q; Tue, 12 Mar 2024 14:38:30 -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 1rk70z-0003Mh-Ne for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:17 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70x-0000cL-0j for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:17 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-41329b6286bso14727815e9.0 for ; Tue, 12 Mar 2024 11:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268693; x=1710873493; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XxETGuhhBQo6mApLsduj7FC9ZSriYQJnVDPgySwv8KY=; b=FsPkBAIvLRzG7OfBAwYq7BywGOs4oQkJxpOec3xQdU+r7w9IW6pnoXrPZi8UfhD/kR rC9WBfyLpbebc8vANlQzDRJwV7DL7PGDqkiPNcsOCzJ9Kf9gevymKm3ZM7yrYKXW3h1e zfPY9RzR/j2P7YT/PMvkIyP+cXD5qtUUyNAGygsgYpgwhEXia0sVajy3/2mfDp+13H1E XJTNC4is7ehzUG7dLRw4RFVLmn+X7VRo23lPymojV8A0Sa1yAXPEKTqxQ8R7Mtgq34kt zwmEiiJZZQL9TV5Q1sUdPRz6PsGBPH82UW23W6lTUBOZ8MMv7YNl+UKqmK+/+l6hW7AJ YUPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268693; x=1710873493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XxETGuhhBQo6mApLsduj7FC9ZSriYQJnVDPgySwv8KY=; b=ljKhcpj6spaEvpiFP2Klq7QuaNYMF7J1iUscM/GdcVXjnsD5QswaLO28zs9/TlNxFE Sycf49h9Bu5E1hmfYGsmOchL1/yDBpzKKDjL4TzgDjjFjFEkvSx9eqqUYIKz7+aD3BYP +RRuZxDqZi7zK2FuHsx85DOUKv9G76wtZdq9HIYX2g/uycjT/b3jzhGcACwF3YWQjeCF 0lQIu2ZRhGe9GOs8Qa0GwJtpfBgtL79hDYXEjHr+5/o8/4o8IQwPUUjHwYXqNUzPFi35 lAHXUHDvYv8M4uyvoznAE0h5yjZ5TXhc2x/tin/0jlF8I2T2sgTKiud2UiQvv52nNf9y +5ew== X-Gm-Message-State: AOJu0YyITBebTpbrR6rJA6sEI9CU77Qsz98PEw6uaF1PNXI7D74QGq/X 8wkqMocX6UPxg1cHktKu5WabzFgOeueipRB3LMv+SARtQlHvKJLdMeIEFCVrVlCyQy/gJAHbsiI D X-Google-Smtp-Source: AGHT+IFpuQyr3sxFxbTV1CiCvOn2uKA/ORryDX/H7nR2om000hMsYM5fQNRFGzs0NkVfQe50tLBt6A== X-Received: by 2002:a05:600c:4708:b0:413:2958:e323 with SMTP id v8-20020a05600c470800b004132958e323mr798783wmo.10.1710268693246; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:13 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 4/7] hw/misc/pca9554: Correct error check bounds in get/set pin functions Date: Tue, 12 Mar 2024 18:38:07 +0000 Message-Id: <20240312183810.557768-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In pca9554_get_pin() and pca9554_set_pin(), we try to detect an incorrect pin value, but we get the condition wrong, using ">" when ">=" was intended. This has no actual effect, because in pca9554_initfn() we use the correct test when creating the properties and so we'll never be called with an out of range value. However, Coverity complains about the mismatch between the check and the later use of the pin value in a shift operation. Use the correct condition. Resolves: Coverity CID 1534917 Signed-off-by: Peter Maydell --- hw/misc/pca9554.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/misc/pca9554.c b/hw/misc/pca9554.c index 778b32e4430..5e31696797d 100644 --- a/hw/misc/pca9554.c +++ b/hw/misc/pca9554.c @@ -160,7 +160,7 @@ static void pca9554_get_pin(Object *obj, Visitor *v, const char *name, error_setg(errp, "%s: error reading %s", __func__, name); return; } - if (pin < 0 || pin > PCA9554_PIN_COUNT) { + if (pin < 0 || pin >= PCA9554_PIN_COUNT) { error_setg(errp, "%s invalid pin %s", __func__, name); return; } @@ -187,7 +187,7 @@ static void pca9554_set_pin(Object *obj, Visitor *v, const char *name, error_setg(errp, "%s: error reading %s", __func__, name); return; } - if (pin < 0 || pin > PCA9554_PIN_COUNT) { + if (pin < 0 || pin >= PCA9554_PIN_COUNT) { error_setg(errp, "%s invalid pin %s", __func__, name); return; } From patchwork Tue Mar 12 18:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 13590507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AA46C54E58 for ; Tue, 12 Mar 2024 18:40:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71C-0003Tx-5p; Tue, 12 Mar 2024 14:38:30 -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 1rk70z-0003Mb-14 for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:17 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70w-0000cN-VT for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:16 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-41329b6286bso14727845e9.0 for ; Tue, 12 Mar 2024 11:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268693; x=1710873493; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rNmtdgrS8nqQbHwAjbW+CEcSMsj64qvynMqUvuKu6rE=; b=PVPqJ4/PF7J4rRdwOH7lbeGROHnwBpYnv9wFwIjeXrLyCx4LQvk6ZYO/p4M9NYS+/9 cmkEpiNxF+RQkXCnFGT0wLmkdE061k9+/+pGFlh3rkk48xMsb1AThLhoj6+SmVDjog2c 2/wgVkHakY3Og8t85uu34sZJtVNKStK5CQ9ftT8mpcSnft53mjZ77TOuF5mJlJAMzlmr FZqVxS8fckopWM2SkKUShRuIccxA7R+62Alu3AuiSCA/XQEmD/+pQSI4WhlaYeS5xQ9c ds73mbSC65uZl0QH2p0LZdV2VELEQbRC2pIlmOGMPTTXVNU86cRVT3fOlDuZwOgGr20H OKwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268693; x=1710873493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rNmtdgrS8nqQbHwAjbW+CEcSMsj64qvynMqUvuKu6rE=; b=cJ8ArTJXvUBGvmYMitjzKR3GztG17vTe/MA7GrNWYX7UHMAXpiZIrC8nq8tcVUaj9+ 2pj1HnJ9WjInJJ9yRGdoVqEFX4pOuQ1ekKzZjXK0CTDhRlvhiCh638gjbUiK67W+Wp1y lNMsLel0ag/neMn9uc/ttTx6IWzXFPVeHsSAxKXJHJkmvqQ6Yx79q3CEKlkr8vFQmbHR jnmUaBmTpdgOKFNEj/d88cQvABwT9lmerIVvhf9LRVIyVC4e/xAgycxRLHqFd7g5WYXj MYjYCEW6dubyY+4GVLkpug9KgwoYzDf0z1ri5O5DUPtXrAaYBuhLLJPOYKpPGRNnlYDP l96g== X-Gm-Message-State: AOJu0YzJKppr4XVm5sOTEH5ep/Mrf+7bYAV/z5S+PJXmB3wAQ+O9x0pP tDQwBqb2H1a3GEi3eHXnCQTeZglhXWwREdZA90SJeiz+kgOqyhSCCOcCXp58zqnXK4K4g6EICB2 n X-Google-Smtp-Source: AGHT+IHkDzX/gjfiMm/bGYHoGySSAolaxSzvda/YmtVcoX3nzjjSqc/KC2K4LpHUXBTVw+qRzTQspw== X-Received: by 2002:a05:600c:1f07:b0:413:1f58:9d15 with SMTP id bd7-20020a05600c1f0700b004131f589d15mr811421wmb.7.1710268693598; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:13 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 5/7] hw/nvram/mac_nvram: Report failure to write data Date: Tue, 12 Mar 2024 18:38:08 +0000 Message-Id: <20240312183810.557768-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There's no way for the macio_nvram device to report failure to write data, but we can at least report it to the user with error_report() as we do in other devices like xlnx-efuse. Spotted by Coverity. Resolves: Coverity CID 1507628 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/nvram/mac_nvram.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c index 5f9d16fb3e3..59277fbc776 100644 --- a/hw/nvram/mac_nvram.c +++ b/hw/nvram/mac_nvram.c @@ -48,7 +48,10 @@ static void macio_nvram_writeb(void *opaque, hwaddr addr, trace_macio_nvram_write(addr, value); s->data[addr] = value; if (s->blk) { - blk_pwrite(s->blk, addr, 1, &s->data[addr], 0); + if (blk_pwrite(s->blk, addr, 1, &s->data[addr], 0) < 0) { + error_report("%s: write of NVRAM data to backing store failed", + blk_name(s->blk)); + } } } From patchwork Tue Mar 12 18:38:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 13590506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10342C54E58 for ; Tue, 12 Mar 2024 18:40:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71E-0003Xa-3z; Tue, 12 Mar 2024 14:38:32 -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 1rk710-0003N2-4r for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:18 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70x-0000cR-7b for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:17 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-413e613316cso2016935e9.1 for ; Tue, 12 Mar 2024 11:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268694; x=1710873494; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GSQdrQ1n3f4UDvq+g8f2/lXlL51/iuaHiFWXMRnbpHk=; b=yWuGgLDH0SG/GSl56ftf3mrv1jLw4be21RNZYFnEX/v5FaOnAalPe2Wdt5FY7B11KW LiDkV6j3pxZ2Te6Je1lH43F8d9jkfDI1Z63D5Z8HWw3UocL0Uk3SQZkd7umOjBl6rLYX 8XRkmOHvrJA/NYy3hLiw+QxS1NbugtREW4l7+3D5KDh8sFKts6sw17q7ZKWWy4yvlCxP IX+ePkzBUNZ3dl5PxLftRU3xRrEDD7FciIUpHBvlwmslJtvXw6z1pye2Uuetsi3HeimY 91EUKw4UFHPheWTbgZWscHmaOGSQJ4fqg8BFabYIR7ex5LTDE3GUDtvMpmEdXAEqkEdr FX7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268694; x=1710873494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GSQdrQ1n3f4UDvq+g8f2/lXlL51/iuaHiFWXMRnbpHk=; b=Ug4pAfyFWQ/dvgKkn1GZVnHY4rrw6mA3sL4gUyQMrKGF7VfBgIbXOEpGiSgz9Y55Yb XseWqE8VxWv36TIkS8g5VrPzRjbVy0S+RX4P0oSqksE8/eayKbsGTy01cYW0fCyBKbVZ Jrqlc8vVh1WpN+wGEfy6oNHSkZ04vURAnk169kgtveFeGBv7uFbBRR44KEGDbwyg0j8h za9ul227IyZbpNoIrVqfhJTC1PTdGtNxYrSSY7esbdeYfhBtQvctyrVRTqB9+8fsEm6C QUNV3gMLQ5lKaTfUi00pNOdKYzG4+ZIgt8DmIghzihJ7mn01Km03a9RXhse6oGFl4oF1 mjUA== X-Gm-Message-State: AOJu0YyH1dLB/n7OJG3LQNsXSThKD/vU5rp5GI22b9zsvugbjA+m7V+0 IajuR0feHoHCP3kEFHyu8k/jfNq7FFou9U3UjEpevVbuGZjiKXxSoWJ97NjNCUg11dqO1aYQexd p X-Google-Smtp-Source: AGHT+IEx/YWUcmrMNb9rhAM5dFAhJDEne/9R9nXJVNkeukLfQHkOvmqyHlxWIYtBvuJkHMfyyTzPlg== X-Received: by 2002:a05:600c:458d:b0:413:2779:8e29 with SMTP id r13-20020a05600c458d00b0041327798e29mr5515991wmo.19.1710268693958; Tue, 12 Mar 2024 11:38:13 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:13 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 6/7] tests/unit/test-throttle: Avoid unintended integer division Date: Tue, 12 Mar 2024 18:38:09 +0000 Message-Id: <20240312183810.557768-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In test_compute_wait() we do double units = bkt.max / 10; which does an integer division and then assigns it to a double variable, and similarly later on in the expression for an assertion. Use 10.0 so that we do a floating point division and calculate the exact value, rather than doing an integer division. Spotted by Coverity. Resolves: Coverity CID 1432564 Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth --- tests/unit/test-throttle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c index 2146cfacd36..24032a02667 100644 --- a/tests/unit/test-throttle.c +++ b/tests/unit/test-throttle.c @@ -127,13 +127,13 @@ static void test_compute_wait(void) bkt.avg = 10; bkt.max = 200; for (i = 0; i < 22; i++) { - double units = bkt.max / 10; + double units = bkt.max / 10.0; bkt.level += units; bkt.burst_level += units; throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 10); wait = throttle_compute_wait(&bkt); g_assert(double_cmp(bkt.burst_level, 0)); - g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10)); + g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10.0)); /* We can do bursts for the 2 seconds we have configured in * burst_length. We have 100 extra milliseconds of burst * because bkt.level has been leaking during this time. From patchwork Tue Mar 12 18:38:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 13590503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92468C54E5D for ; Tue, 12 Mar 2024 18:39:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rk71D-0003Wo-Jz; Tue, 12 Mar 2024 14:38:31 -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 1rk710-0003N6-8A for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:19 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rk70x-0000cW-MO for qemu-devel@nongnu.org; Tue, 12 Mar 2024 14:38:18 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4133100bccdso9412895e9.0 for ; Tue, 12 Mar 2024 11:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710268694; x=1710873494; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=F5TgssMb195QO0ZRrXOaRa+rjmUvH1NGzSH3Wll6Fnw=; b=hMfWKLE5AxQwmn41SKLaRp/xO5wwJwTHhSFHLkoSTBACEurGgfsK4OSWP2/WQDzj/o xFS8YMg/lqbQ0mYGy9pc3zSvStea9TDx6SwbAcT4ITTevnm0mo50YTNRnQVzzC7cjmGI j1eU5RU3MJZcU/GKls4+CsukvBeT23fuh+2SV7JSQ8pl13DhWOvZvVF0AgXnwZsdh2He W4xQa2vZsqbtkn18sOuIONjTUbYvLC4q4PdvXFIJWOWHzTwQlcK2ItNR+TlOQFJMukz6 ERWBb+dAAMu5xeQCSkWJTvDfWHdwN903B2UHSppZv6a4ARLBEvWGQvvjX3c2GwU5i18R gF6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268694; x=1710873494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F5TgssMb195QO0ZRrXOaRa+rjmUvH1NGzSH3Wll6Fnw=; b=Kj0/XY/asZPKMozyFlJmseRST33MJv4+dN5VVGTo0tbnVu1d50yr2QU6XN9eqG7hyO cl4Zzc0VS7ixae2TJla8qEvGSlHKAh1i4CnSQVdM2MkpPaCAxo5FJ1VxuF0swKrq1m2j kP4har9DK9kzUFGVOrpxt9d49ghglLqlsyrIUAWDqi74xt5/KiY+F8mV3OVLgYZYK8ep N1kK+d5dK7TKOp78sS+eK5hZPkZEKrH87C5FmsZpXAVW2xQWKNBap8mTCjDVcKig/Olb 7Rm+f8iJH0n8qrk2ePWEwHWBoCJx1HnCLg5ubGs8b5bWgEOW3hZU7ht4jRZvSc5sQR8j ofMQ== X-Gm-Message-State: AOJu0YwesTITl9eR1QERaosJTmhSZv/gEMrn1lpLgWdC39lRU6r9tJzF 6SMPUtV6s6LRkk4WQTHrNxeKNH88ZuqGa0RvUldGEdf19nSO7kvi8oNULClyIDNqIFlxpQEVGjn 7 X-Google-Smtp-Source: AGHT+IGq9kJXvc10MuvsO5ujDoDaQDnM4ynzQdE718yRq2UBDtH365OgrAlqBCi+sOjH1x64XGNNPA== X-Received: by 2002:a05:600c:1d12:b0:413:2ea4:1731 with SMTP id l18-20020a05600c1d1200b004132ea41731mr3970648wms.15.1710268694341; Tue, 12 Mar 2024 11:38:14 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v17-20020a05600c471100b00412ee8e2f2asm19836337wmo.9.2024.03.12.11.38.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:38:14 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 7/7] tests/qtest/libqtest.c: Check for g_setenv() failure Date: Tue, 12 Mar 2024 18:38:10 +0000 Message-Id: <20240312183810.557768-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312183810.557768-1-peter.maydell@linaro.org> References: <20240312183810.557768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Coverity points out that g_setenv() can fail and we don't check for this in qtest_inproc_init(). In practice this will only fail if a memory allocation failed in setenv() or if the caller passed an invalid architecture name (e.g. one with an '=' in it), so rather than requiring the callsite to check for failure, make g_setenv() failure fatal here, similarly to what we did in commit aca68d95c515. Resolves: Coverity CID 1497485 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/libqtest.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index f33a2108610..d8f80d335e7 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1814,7 +1814,11 @@ QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch, * way, qtest_get_arch works for inproc qtest. */ gchar *bin_path = g_strconcat("/qemu-system-", arch, NULL); - g_setenv("QTEST_QEMU_BINARY", bin_path, 0); + if (!g_setenv("QTEST_QEMU_BINARY", bin_path, 0)) { + fprintf(stderr, + "Could not set environment variable QTEST_QEMU_BINARY\n"); + exit(1); + } g_free(bin_path); return qts;