From 57f01363743fec27af998a2083ad8c5c0f6d7516 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 10 Apr 2019 16:37:42 -0400 Subject: [PATCH] Fix tests: NULL pointer dereference in ust channel unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The test_create_ust_channel() test case erroneously checks for a NULL session instead of a channel. This can result in a NULL pointer dereference on failure to create a ust channel. The scope of usess is reduced to prevent similar mistakes in the future. Moving 'dom' has made it obvious that this variable is unused. Hence, it is removed. Signed-off-by: Jérémie Galarneau --- tests/unit/test_ust_data.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_ust_data.c b/tests/unit/test_ust_data.c index 35e1b87a0..5353052a5 100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.c @@ -58,9 +58,6 @@ static const char alphanum[] = "abcdefghijklmnopqrstuvwxyz"; static char random_string[RANDOM_STRING_LEN]; -static struct ltt_ust_session *usess; -static struct lttng_domain dom; - /* * Return random string of 10 characters. * Not thread-safe. @@ -80,9 +77,9 @@ static char *get_random_string(void) static void test_create_one_ust_session(void) { - dom.type = LTTNG_DOMAIN_UST; + struct ltt_ust_session *usess = + trace_ust_create_session(42); - usess = trace_ust_create_session(42); ok(usess != NULL, "Create UST session"); if (!usess) { @@ -112,8 +109,8 @@ static void test_create_ust_channel(void) uchan = trace_ust_create_channel(&attr, LTTNG_DOMAIN_UST); ok(uchan != NULL, "Create UST channel"); - if (!usess) { - skip(1, "UST session is null"); + if (!uchan) { + skip(1, "UST channel is null"); return; } -- 2.34.1