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: 779771 Delivered-To: patch@linaro.org Received: by 2002:a5d:604e:0:b0:33e:7753:30bd with SMTP id j14csp2168358wrt; Tue, 12 Mar 2024 11:40:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXEL58XAhIOdnHmaUs2CowSZTtmOwkAX1HD4bk98FBSJF9esIJtGYDfJIzAVgsoVjMAGkm3KGJ6R+Ad/xFEwbOi X-Google-Smtp-Source: AGHT+IHbIubVYvEvTSvZjlpcG4nRzvewbDk+jsff4NIPNbbp/W03PVCxHaV85X6Ehxb540tu3biv X-Received: by 2002:a05:6830:12c5:b0:6e5:220c:7ec4 with SMTP id a5-20020a05683012c500b006e5220c7ec4mr10840533otq.16.1710268808742; Tue, 12 Mar 2024 11:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710268808; cv=none; d=google.com; s=arc-20160816; b=q++Mp2LSgH5aqeVsCPnUEKS99CZdfUK5loZLHNG0JHJjoXBl07aJUA+Hok+QJVvvGm /ne1sskZ2HhCLGSdpJHX2enYp8y4fSHCjNYRkXSK4uDm0ovK6ihn57Cp0X8ZjDVoQNj5 pRNaDNiiWEK1gcc/RhciqauPySnH9S0FGZ7kwDiIMFLOfO6/0nhxJxOaCNqbAPeZxrPp OMKGhjOHZeLR6QUfTwzL+rQNAXY1q7PKcmmQ1iXBpbJ3KdQgAjUwEyZ4/doG8Y9FvABi ABws3sAK9kLme80GMSRFFxrqFno5HrhsfmP0lmr/M82Rx34VoP79/Ne7arlcPl89TUHW BE5Q== 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:to:from :dkim-signature; bh=09aQF63pPHOllcqpbcVLj8Q606SuNrCw0WJNZs+4sLY=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=KrXtPC64acZye02k1ihRUyaT2ezOZDUVo/+3UHcIMgHRwAVoL97E/k5TZxh7pJBosU K24ShVz0JV4s5cwPS0nHhS/edNa2f3NitPs1Q33aAy9GMf8XfLACL6QdHeAPOT2VAWEW pA8PnUQQ5oDaPE94Tn2O9vuvSOblu7IYyxtLI81ealkzKZalhW291DvJDtDmnRUtqftI /HtYNPQUwLD3KHQj0L0mrv3FL9zysdE2AyyyESBCHv34ccil4YUEC56bCCSLI1p1C7GS 0lqirRyPaAQS8LwGUG3BCq2YcxFqKK4qg1PJu9jOMv/L4OcFA0ciC0WEkXGn2pw4z3GW 48Fg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dL20NEt8; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c24-20020a37e118000000b007882f7f74c6si7981459qkm.257.2024.03.12.11.40.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2024 11:40:08 -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=dL20NEt8; 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 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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; }