From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 2/3] unit/test-sdp-xml: Give each test its own test_data
Date: Fri, 14 Aug 2026 13:47:30 -0400 [thread overview]
Message-ID: <20260814174731.1441738-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260814174731.1441738-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
DEFINE_TEST assigned the filename and expected result to a single
test_data and passed its address to tester_add(), so every test shared
one struct and ran with whatever the last registered test left in it.
All the file based tests therefore parsed the same file, and a test
pointing at a file that does not exist still passed.
That in particular meant compute-seq-size-type-confusion.xml, the
regression test for GHSA-7mmr-gwqx-vc34, was never actually parsed, and
passed only because it inherited the expected result of the test
registered after it.
Use an array with one entry per test instead.
Assisted-by: Claude:claude-opus-5
---
unit/test-sdp-xml.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/unit/test-sdp-xml.c b/unit/test-sdp-xml.c
index b338788aa295..72e01f5f5806 100644
--- a/unit/test-sdp-xml.c
+++ b/unit/test-sdp-xml.c
@@ -114,25 +114,35 @@ static void sequence_on_squared_teardown(gconstpointer data)
tester_teardown_complete();
}
-#define DEFINE_TEST(fname, res) { \
- data.expected_result = res; \
- data.filename = fname; \
- tester_add("/" fname, &data, NULL, \
- parse_xml_for_filename, NULL); \
- }
+#define DEFINE_TEST(fname, res) { .filename = fname, .expected_result = res }
+
+/*
+ * Each test needs its own test_data, sharing a single one would make every
+ * test run with the values assigned by the last one registered.
+ */
+static struct test_data file_tests[] = {
+ DEFINE_TEST("Bluetooth_HID-sdp_record.xml", TRUE),
+ DEFINE_TEST("qt-SerialPortSDPRecord.xml", TRUE),
+ /* From https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34 */
+ DEFINE_TEST("compute-seq-size-type-confusion.xml", FALSE),
+ /* From https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc */
+ DEFINE_TEST("duplicate-attribute.xml", TRUE),
+};
int main(int argc, char *argv[])
{
struct test_data data;
+ unsigned int i;
tester_init(&argc, &argv);
- DEFINE_TEST("Bluetooth_HID-sdp_record.xml", TRUE);
- DEFINE_TEST("qt-SerialPortSDPRecord.xml", TRUE);
- /* From https://github.com/bluez/bluez/security/advisories/GHSA-7mmr-gwqx-vc34 */
- DEFINE_TEST("compute-seq-size-type-confusion.xml", FALSE);
- /* From https://github.com/bluez/bluez/security/advisories/GHSA-75v6-6q44-57hc */
- DEFINE_TEST("duplicate-attribute.xml", TRUE);
+ for (i = 0; i < G_N_ELEMENTS(file_tests); i++) {
+ char *name = g_strdup_printf("/%s", file_tests[i].filename);
+
+ tester_add(name, &file_tests[i], NULL,
+ parse_xml_for_filename, NULL);
+ g_free(name);
+ }
tester_add("/sequence_on_squared", &data,
sequence_on_squared_setup,
--
2.54.0
next prev parent reply other threads:[~2026-08-14 17:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 17:47 [PATCH BlueZ v1 1/3] sdp-xml: Fix leaking the parse stack on malformed input Luiz Augusto von Dentz
2026-08-14 17:47 ` Luiz Augusto von Dentz [this message]
2026-08-17 8:41 ` [PATCH BlueZ v1 2/3] unit/test-sdp-xml: Give each test its own test_data Bastien Nocera
2026-08-17 18:43 ` Luiz Augusto von Dentz
2026-08-14 17:47 ` [PATCH BlueZ v1 3/3] sdp: Fix memory leak when freeing alternates Luiz Augusto von Dentz
2026-08-14 19:43 ` [BlueZ,v1,1/3] sdp-xml: Fix leaking the parse stack on malformed input bluez.test.bot
2026-08-18 18:37 ` [PATCH BlueZ v1 1/3] " patchwork-bot+bluetooth
2026-09-10 17:42 ` [BlueZ,v1,1/3] " bluez.test.bot
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=20260814174731.1441738-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.