From: Oliver Chang <ochang@google.com>
To: linux-bluetooth@vger.kernel.org
Cc: oss-fuzz-bugs@google.com, Oliver Chang <ochang@google.com>
Subject: [PATCH BlueZ 1/1] Fixed heap-buffer-overflow in `compute_seq_size`.
Date: Fri, 8 Aug 2025 01:34:02 +0000 [thread overview]
Message-ID: <20250808013402.548986-2-ochang@google.com> (raw)
In-Reply-To: <20250808013402.548986-1-ochang@google.com>
By adding checks for sequence/alternate types in element_end and
ensuring proper cleanup in sdp_xml_parse_record error path.
https://issues.oss-fuzz.com/issues/42516062
https://oss-fuzz.com/testcase-detail/5896441415729152
---
src/sdp-xml.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 5efa62ab8..b10882db2 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -545,6 +545,13 @@ static void element_end(GMarkupParseContext *context,
}
if (!strcmp(element_name, "sequence")) {
+ if (!SDP_IS_SEQ(ctx_data->stack_head->data->dtd)) {
+ g_set_error(err, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+ "Unexpected data type %d for sequence",
+ ctx_data->stack_head->data->dtd);
+ return;
+ }
+
ctx_data->stack_head->data->unitSize = compute_seq_size(ctx_data->stack_head->data);
if (ctx_data->stack_head->data->unitSize > USHRT_MAX) {
@@ -557,6 +564,13 @@ static void element_end(GMarkupParseContext *context,
ctx_data->stack_head->data->unitSize += sizeof(uint8_t);
}
} else if (!strcmp(element_name, "alternate")) {
+ if (!SDP_IS_ALT(ctx_data->stack_head->data->dtd)) {
+ g_set_error(err, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+ "Unexpected data type %d for alternate",
+ ctx_data->stack_head->data->dtd);
+ return;
+ }
+
ctx_data->stack_head->data->unitSize = compute_seq_size(ctx_data->stack_head->data);
if (ctx_data->stack_head->data->unitSize > USHRT_MAX) {
@@ -621,6 +635,11 @@ sdp_record_t *sdp_xml_parse_record(const char *data, int size)
if (g_markup_parse_context_parse(ctx, data, size, NULL) == FALSE) {
error("XML parsing error");
g_markup_parse_context_free(ctx);
+ while (ctx_data->stack_head) {
+ struct sdp_xml_data *elem = ctx_data->stack_head;
+ ctx_data->stack_head = elem->next;
+ sdp_xml_data_free(elem);
+ }
sdp_record_free(record);
free(ctx_data);
return NULL;
--
2.50.1.703.g449372360f-goog
next prev parent reply other threads:[~2025-08-08 1:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 1:34 [PATCH BlueZ 0/1] Fixed a buffer overflow found by OSS-Fuzz Oliver Chang
2025-08-08 1:34 ` Oliver Chang [this message]
2025-08-08 4:30 ` bluez.test.bot
2025-08-08 9:34 ` [PATCH BlueZ 1/1] Fixed heap-buffer-overflow in `compute_seq_size` Bastien Nocera
[not found] ` <CAFqAZOL4iKjuxa=ubwFCGHyfgtuGBCW7F1US=1sYSoeWiMZpTg@mail.gmail.com>
2025-08-08 11:45 ` Oliver Chang
2025-08-08 14:08 ` Bastien Nocera
-- strict thread matches above, loose matches on Subject: below --
2025-08-10 6:46 [PATCH BlueZ 0/1] *** Fixed heap-buffer-overflow in `compute_seq_size` *** Oliver Chang
2025-08-10 6:46 ` [PATCH BlueZ 1/1] Fixed heap-buffer-overflow in `compute_seq_size` Oliver Chang
2025-08-10 7:22 ` Paul Menzel
2025-08-10 8:20 ` Oliver Chang
2025-08-10 20:20 ` Paul Menzel
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=20250808013402.548986-2-ochang@google.com \
--to=ochang@google.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=oss-fuzz-bugs@google.com \
/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