Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4808382iob; Mon, 9 May 2022 02:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCxRApeZR13lynWECs9cX1WJDCXkIeHKflQgnzbIg5sm0At/9ao58FUzmN81Nmm8sLQqxH X-Received: by 2002:a63:87c6:0:b0:3c6:a7d9:5d01 with SMTP id i189-20020a6387c6000000b003c6a7d95d01mr5266609pge.341.1652086975495; Mon, 09 May 2022 02:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652086975; cv=none; d=google.com; s=arc-20160816; b=XdzNv0vB+fx4QXJR/IpOJkNddZupkb+pDyvYAH1Gxb5FDWQNFPC8UKf+se5V2VJ90g GK/DU02yM0ehJgD8fdl3zNNrYGgKQfnWS2cPlj7vxpvn/3MvYmXxN1RgznkYTe7GEkVK kLJk7RC9b2p8EoJ0OdA6abbFsMAli42usVme9nsOXIo+Sm1NiFQzhheT4VNiNThVcutE 9pfGWpXwGOD6nL6uIWkYCSgOUYEgF8M+zoqNzmbAUg8LdqBh1TIEdZ6IJ4G3qxtqNisp eAYWpzNlNeC+VG8SsylX+xaH3R7533s23EC1Vq378ydUKFYVqDGyQFBvwjk+lQTBjvmR xwNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-filter; bh=gUpV4hDjciEHEX7tJrBQ0qA+1Xmxazvm6PuD7SfrU8c=; b=UVNqa87dwvUeOvqMTT0MEHn93GtMj3ji63v4JwurqBtPrLNDOicomvh2Pb5RZ4jTAh TsCsBjjDX6zLs300pGgAGlS6RSp16XqMlcqdPT43NgjtbwO0fqaBO8NQxpjvkbYpKJCI OzSHUmMnp9LAysGXGcQF9MEPpCnPSrP2Fdd8By4XEGC9Mr/FrjDAwppGwrOdt2Aiocq+ UMoN4W0vyvTafLTYFgsBwDJ+pEzzQ1f4vNRLAhfI1VJcwZR2MN4Tcmm8G305D+Dc+hH1 qI+VMUt8dBryjZ4RZid4VmnWVAW5o272Uzrtz39UjTCYL6CRhgpha9B3TmP9ybHKpQoh /F7A== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t4-20020a634444000000b003c6dde2affbsi468990pgk.126.2022.05.09.02.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:02:55 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD9591F63BA; Mon, 9 May 2022 01:50:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233409AbiEGRjF (ORCPT + 99 others); Sat, 7 May 2022 13:39:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347443AbiEGRjE (ORCPT ); Sat, 7 May 2022 13:39:04 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FF722B32 for ; Sat, 7 May 2022 10:35:17 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru C5FB120A4941 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 3/4] tools: Fix handle leak in rfcomm Date: Sat, 7 May 2022 20:35:04 +0300 Message-ID: <20220507173505.31249-4-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220507173505.31249-1-i.kamaletdinov@omp.ru> References: <20220507173505.31249-1-i.kamaletdinov@omp.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT01.lancloud.ru (fd00:f066::141) To LFEX1910.lancloud.ru (fd00:f066::80) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Some branches of execution can make handle (socket) leakage. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. --- tools/rfcomm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/rfcomm.c b/tools/rfcomm.c index cd520aa44..e013ff588 100644 --- a/tools/rfcomm.c +++ b/tools/rfcomm.c @@ -298,6 +298,7 @@ static void cmd_connect(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **arg if (setsockopt(sk, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) { perror("Can't set linger option"); + close(sk); return; } } @@ -466,6 +467,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv if (getsockname(nsk, (struct sockaddr *)&laddr, &alen) < 0) { perror("Can't get RFCOMM socket name"); close(nsk); + close(sk); return; } @@ -475,6 +477,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv if (setsockopt(nsk, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) { perror("Can't set linger option"); close(nsk); + close(sk); return; } } @@ -490,6 +493,7 @@ static void cmd_listen(int ctl, int dev, bdaddr_t *bdaddr, int argc, char **argv dev = ioctl(nsk, RFCOMMCREATEDEV, &req); if (dev < 0) { perror("Can't create RFCOMM TTY"); + close(nsk); close(sk); return; } -- 2.35.3