Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4637715iob; Sun, 8 May 2022 20:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOGY5hiHQaPpdzeiRHLXplFFJTauDgl0tyaFkONV4x5f1iSX1PXziSlLulhox1R8Q/dlmT X-Received: by 2002:a17:90a:e517:b0:1da:3d42:7fb8 with SMTP id t23-20020a17090ae51700b001da3d427fb8mr16283369pjy.194.1652065765236; Sun, 08 May 2022 20:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652065765; cv=none; d=google.com; s=arc-20160816; b=G+ksqes/2A6P3rV1lYPz86PZgg+U0f/OytAGMN8+/duFXBUpQPckDEKpOYAu+FYwEJ B9+Xr0baZLQSuFNKy25hWkXatsnQqnbmhmhyM7+U+DykK2jlWzqUwy7gbbVQUhq4s1zV jjriorehaLMioLiulqf+p8tRs5XlmAlqbZNS4byiGIfyG3s776G0IN9qENO3mgiCQt/e j2AYyPxv3YKOLsV7aMqD336dLpFLnygkKA31FE4a1zXsjyK/ykW+lDrQtSXPUiD1nqiP B4F43LpB2Rybr7liqnIB6pg0tjtEWbqqnNVoQQz/LyiUKCxXo062Z+ceBjjsvez80SRE UDqw== 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=z9rCP9miUwZ1MgqRGCQwP/m2cqYQaJ9Nb2gYF1XPimQwa6laT5R5FFhYnCIXKCrJpT 94cTOkqck5HC+lAfDl0ZaAZvLCovsqeluXJL0HYmIXAyflgQLW7fG5Xei1PF4tDZQ2xP iajGALRTm7tCyG5NBq45yCLtK43AsdNS0g4bMdeMRB4S3R0bjnWofMXXz9fb258qROMW nA/HZca2SM41amytu5Ss0qN3lVKx30voMasSnmIwczM7gn7uz459rcBxCTIUabDQYzI2 jbx3WjXmzbYGsmjuS4kDb1c3SJyOQ1Yv2AowB4nCYzLRg/QFJATW4MXHe1l3b2DaJrvN h9VQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k7-20020a056a00134700b004faec051bd4si14041624pfu.242.2022.05.08.20.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:09:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 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 E6BED8BF6D; Sun, 8 May 2022 20:09:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386519AbiEGRLN (ORCPT + 99 others); Sat, 7 May 2022 13:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386522AbiEGRLC (ORCPT ); Sat, 7 May 2022 13:11:02 -0400 Received: from mxout01.lancloud.ru (mxout01.lancloud.ru [45.84.86.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693DC3B3F8 for ; Sat, 7 May 2022 10:07:12 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout01.lancloud.ru 73A6720D605A 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:07:02 +0300 Message-ID: <20220507170703.29902-4-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220507170703.29902-1-i.kamaletdinov@omp.ru> References: <20220507170703.29902-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: LFEXT02.lancloud.ru (fd00:f066::142) 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