Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp451700lqo; Fri, 10 May 2024 05:14:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXXg5rLbKuXTzBSNnOVf0w/czopdN+QKrsJY3Ed/ARMxTsiXvmWpPlz8ctxg6M9FnIcmN9NqkngfgqZc98c0BoidpDasOVOYEUzhTxqmg== X-Google-Smtp-Source: AGHT+IGqv/koQBnjffvA2omfjkIhMTzJRqFVaLePsY14QpW78qaNFUfgDSR7043dt9girCCnqz5S X-Received: by 2002:a50:c31e:0:b0:56e:2d93:3f84 with SMTP id 4fb4d7f45d1cf-5734d5c13d3mr1704836a12.4.1715343261123; Fri, 10 May 2024 05:14:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715343261; cv=pass; d=google.com; s=arc-20160816; b=gU4HRokI1Add+C73eiOD/DFXxE+hPviDxxbhuDkK2IioQdeMna8hIG/EApE00zYFZS nGX5Kz8FAC20bQZkpKNdnylQrMWT7T4rj5hIYmKA++7BS4mzBHRv6N81f7pyhls5GVRb 3TxJ6m1qRQDovJAfvp3OLtOXPU/pS922k+jdS/ATBAhf/NhZr+bt9dKqtYczzYZewgYz xKMUF1l8H28rTZhA5krAED7VffKimD3wPwVRpXbjMfnf08C5us7lHD+lh2ih55XcLkkz C6qdpq7hIhHfEWUteSxoLi7vbZrfSz0QEjZFsODxo+8anC5G+zGBF1QdrD8VN/4UuT76 +dzA== 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:cc:to:from; bh=Lj8A0zJqWsze7oP8g9iDDPQ86YyGGspOX130Jc6uxLI=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=s8AWPRHXAJWGA3UwkYNqDYTzf9lLVzSTLZW7Vi56ZM/jbYz72TY5DI6Rojq/UyMo6K prQa+XnJkmNF53J0Tz+bWMinqikn1JWVmIYjxSZ3AY73B+Sa7iN0v7MJdrX+z+nsRwVC DBtRo0LYKG4JN48R77/I8qoO9V7RbcUmW+Rrr54FqGFt5arbzjIgGfBzTPsr22gVUnsY MWzg4Zs+HtEGyiZ/UnRyUJpsWCgTgbJkGg7o9LJPqkajQPXHZ9jb+GzKeoNlMbdZivK7 V007tIGOHNU+FNeeEnro7SEyLLFYYeiuXkcdaGaTnKBUe21o/bvNbOeXDUq9RrDX1mcy SgYg==; 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-4465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4465-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2e45e6si1896547a12.206.2024.05.10.05.14.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4465-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 am.mirrors.kernel.org (Postfix) with ESMTPS id CAFA31F21C6B for ; Fri, 10 May 2024 12:14:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36FDF17082E; Fri, 10 May 2024 12:14:13 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 4960817085F for ; Fri, 10 May 2024 12:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343251; cv=none; b=fOk5buaOumvJSrWds08mF0qGoavOs/uWtCJ5dOt70Cme/VR7P84dn2PCuMwsfwjuZSI6NvJmHQQlJgrw+6jxm5rj0h4tnhg5mlRqriwY0174Y53Lsbxwdi9VmZJB7FLF6U0ZmAcvzGfVr4XeAN0bC+AfhO4XCE27ruRT4S7URsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715343251; c=relaxed/simple; bh=TmByswNQKHOXRhWykun5laQ2PUPsFpZeRBbgJLQuE2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aS1xSD5B0AXnp0+/s6IHvUp1cCuN23nmzuQqC8ZW5S5dZTQ4LX6Cnrsoe8JNbTjtPoT47b5bHb0saY0IQCGJiH0VTbZ6o8kh2HEFaR0aJ+5qBfO4Ofn+4uRD7EVPZNt5NjJpGeMNMJ4hdmr4Kgt2r6bPsH3GxKsQaIdbyU6fes8= 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.195 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 86A0860005; Fri, 10 May 2024 12:13:56 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ v2 03/20] client/gatt: Don't pass negative fd on error Date: Fri, 10 May 2024 14:10:13 +0200 Message-ID: <20240510121355.3241456-4-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510121355.3241456-1-hadess@hadess.net> References: <20240510121355.3241456-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