Fix tests: NULL pointer dereference in ust channel unit tests
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 10 Apr 2019 20:37:42 +0000 (16:37 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Apr 2019 23:33:48 +0000 (19:33 -0400)
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 <jeremie.galarneau@efficios.com>
tests/unit/test_ust_data.c

index f22f8c4e21fdfcf3db85e9f6a3c8aec161d9cdb3..a12343d7bc14b5afe6f3c9ea5a0d5b216b5369e2 100644 (file)
@@ -60,9 +60,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.
@@ -82,9 +79,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) {
@@ -117,8 +114,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;
        }
 
This page took 0.026179 seconds and 4 git commands to generate.