From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: [BlueZ, v4 4/9] sdp-xml: Fix memory leak when adding duplicate attributes
Date: Wed, 12 Aug 2026 10:01:35 +0200 [thread overview]
Message-ID: <20260812080410.2116906-5-hadess@hadess.net> (raw)
In-Reply-To: <20260812080410.2116906-1-hadess@hadess.net>
When sdp_attr_add() fails because an attribute is duplicated, don't
unset its pointer in the parsing context data. As the attribute wasn't
added to the record, the ownership of the attribute didn't get passed
to the record either.
Don't set the pointer to NULL so it gets freed when cleaning up the
context.
Fixes those 2 ASan warnings:
Direct leak of 48 byte(s) in 1 object(s) allocated from:
#0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x562042b747f2 in sdp_data_alloc_with_length lib/bluetooth/sdp.c:350
Indirect leak of 2 byte(s) in 1 object(s) allocated from:
#0 0x7f896a8ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x562042b74bd7 in sdp_data_alloc_with_length lib/bluetooth/sdp.c:425
See https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc
Reported-by: Aisle Research
Co-authored-by: Aisle Research
---
src/sdp-xml.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index c8f9ed013b29..816d19611f8b 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -537,8 +537,11 @@ static void element_end(GMarkupParseContext *context,
if (ret == -1)
DBG("Could not add attribute 0x%04x",
ctx_data->attr_id);
+ else {
+ /* ownership transferred to record */
+ ctx_data->stack_head->data = NULL;
+ }
- ctx_data->stack_head->data = NULL;
sdp_xml_data_free(ctx_data->stack_head);
ctx_data->stack_head = NULL;
} else if (ctx_data->stack_head && ctx_data->stack_head->next) {
--
2.55.0
next prev parent reply other threads:[~2026-08-12 8:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 8:01 [BlueZ, v4 0/9] 3 SDP XML security fixes Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 1/9] unit: Add test for sdp_xml_parse_record() Bastien Nocera
2026-08-12 9:45 ` 3 SDP XML security fixes bluez.test.bot
2026-08-12 8:01 ` [BlueZ, v4 2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 3/9] unit: Add test for sdp-xml type-confusion bug Bastien Nocera
2026-08-12 8:01 ` Bastien Nocera [this message]
2026-08-12 8:01 ` [BlueZ, v4 5/9] unit: Add test for sdp-xml duplicate attribute bug Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 6/9] sdp-xml: Optimise parsing large sequences Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 7/9] unit: Add test for slow element_end() append Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 8/9] sdp-xml: Fix stack overflow when converting large sequences to XML Bastien Nocera
2026-08-12 8:01 ` [BlueZ, v4 9/9] unit: Add convert_sdp_record_to_xml() to SDP XML testing 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=20260812080410.2116906-5-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