Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp368230lqo; Fri, 10 May 2024 02:18:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXI5RbOaukNP1m9xwjbjPGQUHrr4n+7Vg2EG0VgKVeRxjNIPeubjAVSDqVl3IKjgQ3kfcbtFmCIX8uvoOng9YEw6nK0Fia0VuusDf/YYg== X-Google-Smtp-Source: AGHT+IF6MCMnS9lF7hQRfnSKxW46OOYqbIye8EvbjmPsF1nQbgEzO5+wcv8sxWW7J4cNRHEkdY/J X-Received: by 2002:a05:6214:43c9:b0:6a0:bab8:68a2 with SMTP id 6a1803df08f44-6a1683859b8mr20511496d6.50.1715332728695; Fri, 10 May 2024 02:18:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715332728; cv=pass; d=google.com; s=arc-20160816; b=ML0CUCj/E+x4MTsemVFSEkqXg2+7lIXh802vh7rKweVLCYMuVH/6mM0l4z04SesVaL DgobrQWQFPagD5uXXZdsNwX5MMSBzkh7Ta1YHLZRkbb/rdk+faAj36PChi5JkExNpsZC iK5f1JuzI3RHoSGhxoco7PgquVTTSXQsKiLorqi15BFYIoWri0mM++EAYsRdR+CiIUBx yEChivf3ZyAtc81eK5/q8U2cISkPMRuiyYqBSN7Lu9FDYy5qzE8QYY7TWs9QZcllE/Y9 4vXqQL9ZCRQwyi7nzNZp/Qmc01NLsEUx3R9zOd1XNA1SB90JM0ox21wnuicu6Mgjjd+S E3ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from; bh=Lj8A0zJqWsze7oP8g9iDDPQ86YyGGspOX130Jc6uxLI=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=zni7Y+qr+AigmDo/N39OyLBcuEeulBl2uMKq4aKc89UuCSQBEYJwrifgyXqX+rsJjZ 70hTWJi3BNQ5KuLjfv/jmBBlcSI6s6MbNCWTYvuNd5gf2aO0j5FzEYjTxNZygQoON2Ko L0pOTp2ChhbQQHbp/KcTOD2xq+t1zWONPA1A7iQEFh6/balOM4aOW/X9LvuQM7xAPM5I 6ye80e5c43WK4NXiAF5uxD34vu734upYEugOgjuHDtrrubV2DihrEvkm8YFgY+g/jKkH s1RQMXqhAthkAPTwDOgL8+dWXyS6qJABqJDpQlj7O/62Uos3Qa+gp02SfJJG+tQkg1ZI iMTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2b4e44si32743956d6.319.2024.05.10.02.18.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4451-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7AD6B1C221EF for ; Fri, 10 May 2024 09:18:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F77E165FCB; Fri, 10 May 2024 09:18:26 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CCC81635CD for ; Fri, 10 May 2024 09:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332705; cv=none; b=HSR0cwqVkM5UPhFvuPb1etv1B0wkvJFx8NmQqEgUcm5LK6QEIATqPZnM4hunpWLv/B5ZKRnZz/yz5u+kv3FHDnqckpSQazxxXyhRud2ByCwJako9zVajt9hwAY1PrTRUvgbgXHStiH/cHveGPOlSFnNOmxvTATHTqpZfHfW8Z6o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332705; c=relaxed/simple; bh=TmByswNQKHOXRhWykun5laQ2PUPsFpZeRBbgJLQuE2w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dHM4BLMeNV8TJPz3ZLx/LvTcZlSVsmhZP3kr+s1sx1YSgQIw2Eh3QWfo1eKwoAjr4WmqEUbjkmyJBR6nJPMig33fLKwTGIaON4wNQJ2r+Gh+Vk698qFtSJRp3kd5l90bz1rCJJZpmObsrCZqP3p0qxrQesXAM9wLEHbizaR8m/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id F01211BF20B for ; Fri, 10 May 2024 09:18:15 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Subject: [BlueZ 03/14] client/gatt: Don't pass negative fd on error Date: Fri, 10 May 2024 11:11:01 +0200 Message-ID: <20240510091814.3172988-4-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510091814.3172988-1-hadess@hadess.net> References: <20240510091814.3172988-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net Error: NEGATIVE_RETURNS (CWE-394): [#def33] bluez-5.75/client/gatt.c:973:2: negative_return_fn: Function "io_get_fd(io)" returns a negative number. bluez-5.75/client/gatt.c:973:2: negative_returns: "io_get_fd(io)" is passed to a parameter that cannot be negative. 971| msg.msg_iovlen = iovlen; 972| 973|-> ret = sendmsg(io_get_fd(io), &msg, MSG_NOSIGNAL); 974| if (ret < 0) { 975| ret = -errno; Error: NEGATIVE_RETURNS (CWE-394): [#def34] bluez-5.75/client/gatt.c:1049:2: negative_return_fn: Function "io_get_fd(io)" returns a negative number. bluez-5.75/client/gatt.c:1049:2: assign: Assigning: "fd" = "io_get_fd(io)". bluez-5.75/client/gatt.c:1062:2: negative_returns: "fd" is passed to a parameter that cannot be negative. 1060| msg.msg_iovlen = 1; 1061| 1062|-> bytes_read = recvmsg(fd, &msg, MSG_DONTWAIT); 1063| if (bytes_read < 0) { 1064| bt_shell_printf("recvmsg: %s", strerror(errno)); --- client/gatt.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/gatt.c b/client/gatt.c index 3aaa7a9361b9..6c7603985172 100644 --- a/client/gatt.c +++ b/client/gatt.c @@ -966,11 +966,15 @@ static int sock_send(struct io *io, struct iovec *iov, size_t iovlen) struct msghdr msg; int ret; + ret = io_get_fd(io); + if (ret < 0) + return ret; + memset(&msg, 0, sizeof(msg)); msg.msg_iov = iov; msg.msg_iovlen = iovlen; - ret = sendmsg(io_get_fd(io), &msg, MSG_NOSIGNAL); + ret = sendmsg(ret, &msg, MSG_NOSIGNAL); if (ret < 0) { ret = -errno; bt_shell_printf("sendmsg: %s", strerror(-ret)); @@ -1052,6 +1056,11 @@ static bool sock_read(struct io *io, void *user_data) if (io != notify_io.io && !chrc) return true; + if (fd < 0) { + bt_shell_printf("recvmsg: %s", strerror(-fd)); + return false; + } + iov.iov_base = buf; iov.iov_len = sizeof(buf); -- 2.44.0