Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4828677iob; Mon, 9 May 2022 02:35:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIM+ih4jd66J/coEjFTGn9mIbyctM1V5Sv1v9K4dLeT0Cwtmn4h5TXUAFYkxTMIwA/An7X X-Received: by 2002:a63:580b:0:b0:3c1:a780:59f7 with SMTP id m11-20020a63580b000000b003c1a78059f7mr12469112pgb.76.1652088927947; Mon, 09 May 2022 02:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652088927; cv=none; d=google.com; s=arc-20160816; b=v8hBwi97D7Frvc+Swfs/HFlxzC5GQHbBWw6+/lEOPvqeIoaSYlQQGpSBDbXTQKHvMP BeDZpjD9Tz1sP1HeIa/Qff26/OxIjCcgVOMX2vxp9Bicpf8p4jBlBPsS4eSpcikDhzlc i63/fMAjF7sTDPcMvJE5vuKARuJYkwTgizYV4rxxe4y2KVrFUT1kMY2csyc7LobUn+br ZIDsil7C+a3o7LsFfVxLu6RlZoE4EHAcYA//Oiu5lBMKoNgFqFwwsJ7WjrTmvipI6ZIk bGWIQAcEUuVKcrT26dfaAA0qWFeTWFJbNTtxsXqicoyD27KAGnJYXlp6rZFv/wDL23vy PVTw== 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=fca1kXmLU5OgERoPF3T195MNBMbvTnTWlhwCE7kTbI+qwSePPgiHfxzf9BkreTJf5R PY+hfLyR5Fnu0NRkQh93VmDriwnmTsUa4wJFrNMe3nLDnxwtgnGSlGzprQIyALVUJbtE LGzgitGrWasIW09ptfVoiWxfYV0Waads3Pt5J3uj2BIlmRSZFzR2ME8RcJbaDZxml8T8 TXgNLNLpOpWUci8lXbFvDFu17Or8sbZotM6MdQQMxYKIYpqJDjutKD08WvwpcHehkc5i rhRSamR5Jc4TnP+f0gNqHRXiFJ5dQ+MErRCb0VoBzBkxvZazRsrfsA7tuSjUD15fQ0YY 5yQQ== 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 rm12-20020a17090b3ecc00b001d2d69d3f46si14385032pjb.151.2022.05.09.02.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:35:27 -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 E17E21660AE; Mon, 9 May 2022 02:21:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241614AbiEGPQs (ORCPT + 99 others); Sat, 7 May 2022 11:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238956AbiEGPQo (ORCPT ); Sat, 7 May 2022 11:16:44 -0400 X-Greylist: delayed 351 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 07 May 2022 08:12:56 PDT Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A3B32D1F0 for ; Sat, 7 May 2022 08:12:55 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru 1AB132323A66 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 18:06:56 +0300 Message-ID: <20220507150657.28240-4-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220507150657.28240-1-i.kamaletdinov@omp.ru> References: <20220507150657.28240-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