Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1357165lqb; Thu, 30 May 2024 08:01:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVc3ZR6CvoK8iQxekEZSCayV2quhNXz+FZ04hV6HxY2ni+LQFfdCiWmiapJZ+3dU+nhfYGwanMGIKYWGy1T/bhFwNQ5CcbbPzPmIPSuNQ== X-Google-Smtp-Source: AGHT+IGaOoecZvM1Old9oeKgRpQqCyaN3z86LyFEyY/XfeQws35T7tyaeevby/K8KbBi4QsS+MHa X-Received: by 2002:a17:907:7788:b0:a67:4a2e:aa12 with SMTP id a640c23a62f3a-a674a2eaa9fmr24791166b.25.1717081282631; Thu, 30 May 2024 08:01:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717081282; cv=pass; d=google.com; s=arc-20160816; b=XbrGk48jdL0awmn4XR8lPeANVSHMJemlpf75Ongjy8NTCSa8hQ3Kmw0kM1JSzfIKkn +EmdmCJX2z6bGUxy7AlX5BWQMvQvMGpSNpPxSp2lFB0+1apR7zliyfv39WfnpSPq/OUl CqAZXDZiNWEOyNweEwyRME49T3kFFjzrKEuHWM8w7QbTzb72rcLCFGY0jBVT3Coq9NRl a7N6QTNMdTg7iTIziMGC6xidaEDqE6DvzPh2VmMGQ73MMkjyL2XifmKRY93/XEimNR+S w3SiWK4ODEXDnVjDJBV/IWRVPXJbFcE7z2yPRbhjN/KJSf/JPi5C9w5RbWYukZCgmPrv mv+A== 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=2nkV9M8ywbW1xmKwVUcYzlyJaFVfxWWub6kHbLBUQXI=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=rfE/Py+2NS+qQnEUz66lVhiIjsPKyhj9Ji+pzbkwhbrVSfNQ4HpIy9v1XWhn3hXJf7 5XYPui/tZHT/xCBeMh52ODaFGpM3/bQ0dv0CmkXObX1Q8xsa41wC9WVroI5P/5G98z0w jK0jWWEsdnvc7gsT+EEMsrGMvzLFBKjKX5cFbk/gKYfpzowZotrujGhw57ClSSr7b1vv aIU32FY3hzNs2YISu1c1ONN4/f2OPdisQT+ZnQH8sKCvDD6pVIsgOMgvBAukbi8cy0uT dRbxd7OKWNZu7UiNvr809y7JiuJCOCzhftsntYmNqPpZ2bAetudKsahib9Uwo4y1qTkn bHcQ==; 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-5040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5040-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 a640c23a62f3a-a626cc3744fsi750469566b.367.2024.05.30.08.01.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:01:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5040-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-5040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5040-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 500ED1F230D0 for ; Thu, 30 May 2024 15:01:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C592717F50A; Thu, 30 May 2024 15:01:03 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 BF00017C216 for ; Thu, 30 May 2024 15:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081263; cv=none; b=ChTPISny4YR1wpKG5GroQsPRhJmi1hOX+BU1AWQ4srnd3eLvf4cRrtJJHAr0aF5hcPCtrWCxlK6pSbDXSoqJ8FhQwMPAcBxzRkuP6HbKAd438bSByF1ot+Pop9tFUXyl9FaTiv0F+bKGqd+FhMxL3OdbS97xovUj9AwFPtiaN6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081263; c=relaxed/simple; bh=mqvn619TSm5ld0odQr215jbTYvsACUe3F6Wkz9yu7qU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0Af6bf/59Bnof5b7tsfJEj8nn6du4WLU56O2r3ZCPzRGaABmtHhe2+91EQHUuEiMi1jufLpgbo2J2QiTC0ntHH2ntgEcQyK1FQRolKZ02suIRfXQaTVHLH/59RimxfOjAtK9BMgrdVRoVvO/7yrpl8TRiMP1lhKxud7CwFaxrc= 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.200 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 EAAA220017; Thu, 30 May 2024 15:00:59 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ 8/9] bap: Fix more memory leaks on error Date: Thu, 30 May 2024 16:58:02 +0200 Message-ID: <20240530150057.444585-9-hadess@hadess.net> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530150057.444585-1-hadess@hadess.net> References: <20240530150057.444585-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: RESOURCE_LEAK (CWE-772): [#def32] [important] bluez-5.76/profiles/audio/bap.c:1166:4: alloc_arg: "asprintf" allocates memory that is stored into "path". [Note: The source code implementation of the function has been overridden by a builtin model.] bluez-5.76/profiles/audio/bap.c:1178:5: leaked_storage: Variable "path" going out of scope leaks the storage it points to. 1176| free(l3_caps); 1177| ret = false; 1178|-> goto group_fail; 1179| } 1180| Error: RESOURCE_LEAK (CWE-772): [#def33] [important] bluez-5.76/profiles/audio/bap.c:1166:4: alloc_arg: "asprintf" allocates memory that is stored into "path". [Note: The source code implementation of the function has been overridden by a builtin model.] bluez-5.76/profiles/audio/bap.c:1199:5: leaked_storage: Variable "path" going out of scope leaks the storage it points to. 1197| 1198| if (matched_lpac == NULL || merged_caps == NULL) 1199|-> continue; 1200| 1201| create_stream_for_bis(bap_data, matched_lpac, qos, --- profiles/audio/bap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 3fcf21df58aa..53e7b3e34378 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -1174,6 +1174,7 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, if (!util_iov_pull_u8(&iov, (void *)&l3_caps->iov_len)) { free(l3_caps); + free(path); ret = false; goto group_fail; } @@ -1195,8 +1196,10 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, l2_caps, l3_caps, &matched_lpac, &merged_caps); - if (matched_lpac == NULL || merged_caps == NULL) + if (matched_lpac == NULL || merged_caps == NULL) { + free(path); continue; + } create_stream_for_bis(bap_data, matched_lpac, qos, merged_caps, meta, path); -- 2.45.1