Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp371381lqo; Fri, 10 May 2024 02:26:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVc7bonBSL7s3xHuGmK8Oj5cGx+by+CRH1GCD/IZrXHe+aNDEz95Is4Is+DdbVuB5VlKBRpYdeLvOkXux3KLgejitXifCUSTkSDgWYHjg== X-Google-Smtp-Source: AGHT+IEBigdoJ7NzAIXWLWmSa2JuRHcy3zaYm3TPjczZlm4BL9QTegNwSxg9uAf7Rhgz4cRxnIIz X-Received: by 2002:a17:902:ea10:b0:1ea:2753:2b9f with SMTP id d9443c01a7336-1ef43d15560mr25088825ad.20.1715333195170; Fri, 10 May 2024 02:26:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715333195; cv=pass; d=google.com; s=arc-20160816; b=pyvC1ZAV+ImlsANJhT11OY4NGR7TUdhLxXWF7YM9hQ1fzp2bTpxnKb6ADN9wfJZL5b 9LAv91fPgPjlJ9Bc7fDz2IM6XtaSfHXm+sKqcGL0wfvLhy06prXW0JgmqVQNPtf5omL0 4p5MtXndKlt+bPLC5ZUOSCRqekTG7p2IcLbGU/7dOJskrEDtQ+VNR/X5yKpb1F+Ebp+6 6kb8JO/Kmq7zn7hcoloQr31m+idglYD0sOB0TxOrAfUBz1uGmLQN/vgWqqu/9ensUvSn xpcD8PSBWSMBGLQ4lylMawVyfwXrc+tcr49ui9T4Ht2dpdYIivDy+7QUdTqrGWD3cH1D EteQ== 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:to:from; bh=uKHKnNlxuxpB1lfKvq8YncblUXrQXy8bmbVf1Psubm0=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=a136nik9p+eOemKzgegEtVO+517rxG22v+49Uy3tcvlw7SKFcC5fci9OZFwBxpGtA+ cENgxmBGX399exbPQ6R6JwgRA13vIMZBI/SEdDG3jmAa38L1p5RbSUkwyC7yLzuiaQ1q jAdNkHBFqTQQEJ6PEzP3Zml8tP4BX2la3AFEwuW4hRSVTeJtSRVxjWs/oKn7XkGOkR3f +ulgURl153jAimWVzhWtEH+NOyWUIGcfJ67epIVxuOyOTRNk1NUmWjHVP5abYwLqJrUf QGm4OgtxWm6QCqKEfrYtW58ysiBvohp5aYfH7r0w8STfn1G2OaUYd7+w5MjEBLFnZkdl cZKw==; 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-4457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4457-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0b9cf1ecsi31814465ad.75.2024.05.10.02.26.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 02:26:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4457-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4457-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 41F6228684B for ; Fri, 10 May 2024 09:19:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7927816ABCC; Fri, 10 May 2024 09:18:28 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (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 7290C1635CD for ; Fri, 10 May 2024 09:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332708; cv=none; b=gu1m5yVB7BsreN576lCMnzSyFExfqh7F+5rSHuttapbQIee6rVv31EdQDKcBkXQCrzhBZSlz5XY2Qt195pTeJl7aCzA/A7CnoMROxXqMd9gDHQSNNmSUhFOWjfHNp2KZxSAUi3h1yublKvMQtx9jx8YtbCljZzgoKLeEXFsKjA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715332708; c=relaxed/simple; bh=KfzM9M9j5GTuPghCb5LA3rp6JbWwmqCc2mF+vpZC2oQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qgpuaMIFnC6m+qPeVlgFhw0De4gTWiRP51v68DRLh/yQ3JVkFU1/Ssjp479rpqVzYVIvo5/L4OpSxgyniS7MWjvUuzBu0fDO0PtVvq570zKUtXCshnpy+ik0ulS13Ic5ypvthOiWtqlV0PfuOGD7Cov3qwAksebL6QoRRl36fdA= 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.201 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 5D3561BF20E for ; Fri, 10 May 2024 09:18:17 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Subject: [BlueZ 10/14] main: Fix memory leaks Date: Fri, 10 May 2024 11:11:08 +0200 Message-ID: <20240510091814.3172988-11-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510091814.3172988-1-hadess@hadess.net> References: <20240510091814.3172988-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): [#def51] [important] bluez-5.75/src/main.c:451:2: alloc_arg: "parse_config_string" allocates memory that is stored into "str". bluez-5.75/src/main.c:454:2: identity_transfer: Passing "str" as argument 1 to function "strtol", which sets "endptr" to that argument. bluez-5.75/src/main.c:456:3: noescape: Assuming resource "str" is not freed or pointed-to as ellipsis argument to "btd_error". bluez-5.75/src/main.c:457:3: leaked_storage: Variable "endptr" going out of scope leaks the storage it points to. bluez-5.75/src/main.c:457:3: leaked_storage: Variable "str" going out of scope leaks the storage it points to. 455| if (!endptr || *endptr != '\0') { 456| error("%s.%s = %s is not integer", group, key, str); 457|-> return false; 458| } 459| Error: RESOURCE_LEAK (CWE-772): [#def52] [important] bluez-5.75/src/main.c:451:2: alloc_arg: "parse_config_string" allocates memory that is stored into "str". bluez-5.75/src/main.c:454:2: identity_transfer: Passing "str" as argument 1 to function "strtol", which sets "endptr" to that argument. bluez-5.75/src/main.c:463:3: leaked_storage: Variable "endptr" going out of scope leaks the storage it points to. bluez-5.75/src/main.c:463:3: leaked_storage: Variable "str" going out of scope leaks the storage it points to. 461| warn("%s.%s = %zu is out of range (< %zu)", group, key, tmp, 462| min); 463|-> return false; 464| } 465| Error: RESOURCE_LEAK (CWE-772): [#def53] [important] bluez-5.75/src/main.c:451:2: alloc_arg: "parse_config_string" allocates memory that is stored into "str". bluez-5.75/src/main.c:454:2: identity_transfer: Passing "str" as argument 1 to function "strtol", which sets "endptr" to that argument. bluez-5.75/src/main.c:475:2: leaked_storage: Variable "endptr" going out of scope leaks the storage it points to. bluez-5.75/src/main.c:475:2: leaked_storage: Variable "str" going out of scope leaks the storage it points to. 473| *val = tmp; 474| 475|-> return true; 476| } 477| --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 23af6781d931..ac840d684f6d 100644 --- a/src/main.c +++ b/src/main.c @@ -454,21 +454,25 @@ static bool parse_config_int(GKeyFile *config, const char *group, tmp = strtol(str, &endptr, 0); if (!endptr || *endptr != '\0') { error("%s.%s = %s is not integer", group, key, str); + g_free(str); return false; } if (tmp < min) { + g_free(str); warn("%s.%s = %zu is out of range (< %zu)", group, key, tmp, min); return false; } if (tmp > max) { + g_free(str); warn("%s.%s = %zu is out of range (> %zu)", group, key, tmp, max); return false; } + g_free(str); if (val) *val = tmp; -- 2.44.0