public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Cc: Bastien Nocera <hadess@hadess.net>
Subject: [BlueZ v2 10/20] main: Fix memory leaks
Date: Fri, 10 May 2024 14:10:20 +0200	[thread overview]
Message-ID: <20240510121355.3241456-11-hadess@hadess.net> (raw)
In-Reply-To: <20240510121355.3241456-1-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


  parent reply	other threads:[~2024-05-10 12:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10 12:10 [BlueZ v2 00/20] Fix a number of static analysis issues Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 01/20] adapter: Use false instead of 0 for bool Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 02/20] attrib/gatt: Guard against possible integer overflow Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 03/20] client/gatt: Don't pass negative fd on error Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 04/20] client/gatt: Check write_value() retval Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 05/20] client/main: Fix array access Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 06/20] client/main: Fix mismatched free Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 07/20] monitor/att: Fix memory leak Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 08/20] bap: Fix memory leaks Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 09/20] media: Fix memory leak Bastien Nocera
2024-05-10 12:10 ` Bastien Nocera [this message]
2024-05-10 12:10 ` [BlueZ v2 11/20] isotest: Consider "0" fd to be valid Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 12/20] isotest: Fix error check after opening file Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 13/20] client/player: Fix copy/paste error Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 14/20] shared/vcp: " Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 15/20] isotest: Fix fd leak Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 16/20] iso-tester: " Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 17/20] sdp: Fix use of uninitialised memory Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 18/20] monitor: Work-around memory leak warning Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 19/20] avrcp: Fix uninitialised memory usage Bastien Nocera
2024-05-10 12:10 ` [BlueZ v2 20/20] main: Simplify variable assignment Bastien Nocera
2024-05-10 15:40 ` [BlueZ v2 00/20] Fix a number of static analysis issues patchwork-bot+bluetooth
2024-05-10 16:42   ` Luiz Augusto von Dentz
2024-05-14 10:05     ` Bastien Nocera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240510121355.3241456-11-hadess@hadess.net \
    --to=hadess@hadess.net \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox