From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Subject: [BlueZ, v3 8/9] sdp-xml: Fix stack overflow when converting large sequences to XML
Date: Tue, 11 Aug 2026 16:54:11 +0200 [thread overview]
Message-ID: <20260811145704.1766949-9-hadess@hadess.net> (raw)
In-Reply-To: <20260811145704.1766949-1-hadess@hadess.net>
Don't make convert_raw_data_to_xml() call itself recursively X times
if there are X elements in a sequence.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1684518==ERROR: AddressSanitizer: stack-overflow on address 0x7fff7fb40d98 (pc 0x7fbe1ee95c2b bp 0x7fff7fb41610 sp 0x7fff7fb40d70 T0)
#0 0x7fbe1ee95c2b in printf_common(void*, char const*, __va_list_tag*) (/lib64/libasan.so.8+0x95c2b) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#1 0x7fbe1eeb72d6 in vsnprintf (/lib64/libasan.so.8+0xb72d6) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#2 0x7fbe1eeb94f4 in snprintf (/lib64/libasan.so.8+0xb94f4) (BuildId: 5395ec74f54d9ec7bf97c06583dd39a96c230822)
#3 0x000000401fc2 in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709
#4 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994
[...]
#246 0x000000401c4f in convert_raw_data_to_xml ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:994
SUMMARY: AddressSanitizer: stack-overflow ../../../../Projects/jhbuild/bluez/src/sdp-xml.c:709 in convert_raw_data_to_xml
---
src/sdp-xml.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 97fb8b0c1af0..0dcb8a7df601 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -679,8 +679,10 @@ sdp_record_t *sdp_xml_parse_record(const char *data, int size)
return record;
}
-
static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
+ void *data, void (*appender)(void *, const char *));
+
+static inline void convert_raw_data_to_xml_element(sdp_data_t *value, int indent_level,
void *data, void (*appender)(void *, const char *))
{
int i, hex;
@@ -999,8 +1001,14 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
break;
}
+}
- convert_raw_data_to_xml(value->next, indent_level, data, appender);
+static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
+ void *data, void (*appender)(void *, const char *))
+{
+ for (; value != NULL; value = value->next) {
+ convert_raw_data_to_xml_element(value, indent_level, data, appender);
+ }
}
struct conversion_data {
--
2.55.0
next prev parent reply other threads:[~2026-08-11 15:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 14:54 [BlueZ, v3 0/9] 3 SDP XML security fixes Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 1/9] unit: Add test for sdp_xml_parse_record() Bastien Nocera
2026-08-11 16:33 ` 3 SDP XML security fixes bluez.test.bot
2026-08-11 14:54 ` [BlueZ, v3 2/9] sdp-xml: Fix crash caused by type confusion when parsing crafted SDP XML Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 3/9] unit: Add test for sdp-xml type-confusion bug Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 4/9] sdp-xml: Fix memory leak when adding duplicate attributes Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 5/9] unit: Add test for sdp-xml duplicate attribute bug Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 6/9] sdp-xml: Optimise parsing large sequences Bastien Nocera
2026-08-11 14:54 ` [BlueZ, v3 7/9] unit: Add test for slow element_end() append Bastien Nocera
2026-08-11 14:54 ` Bastien Nocera [this message]
2026-08-11 14:54 ` [BlueZ, v3 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=20260811145704.1766949-9-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