[lttng-dev] [PATCH lttng-tools 1/3] Fix: test_kernel_data dereference of null pointer

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Tue Jan 17 15:02:08 UTC 2017


Skip tests when tested struct is null.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 tests/unit/test_kernel_data.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tests/unit/test_kernel_data.c b/tests/unit/test_kernel_data.c
index 5bca684..6a35ea5 100644
--- a/tests/unit/test_kernel_data.c
+++ b/tests/unit/test_kernel_data.c
@@ -72,6 +72,10 @@ static void test_create_one_kernel_session(void)
 	kern = trace_kernel_create_session();
 	ok(kern != NULL, "Create kernel session");
 
+	if (!kern) {
+		skip(1, "Kernel session is null");
+		return;
+	}
 	ok(kern->fd == -1 &&
 	   kern->metadata_stream_fd == -1 &&
 	   kern->consumer_fds_sent == 0 &&
@@ -117,6 +121,11 @@ static void test_create_kernel_channel(void)
 	chan = trace_kernel_create_channel(&attr);
 	ok(chan != NULL, "Create kernel channel");
 
+	if (!chan) {
+		skip(1, "Channel is null");
+		return;
+	}
+
 	ok(chan->fd == -1 &&
 	   chan->enabled == 1 &&
 	   chan->stream_count == 0 &&
@@ -143,6 +152,11 @@ static void test_create_kernel_event(void)
 	event = trace_kernel_create_event(&ev, NULL, NULL);
 	ok(event != NULL, "Create kernel event");
 
+	if (!event) {
+		skip(1, "Event is null");
+		return;
+	}
+
 	ok(event->fd == -1 &&
 	   event->enabled == 1 &&
 	   event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT &&
@@ -161,6 +175,11 @@ static void test_create_kernel_stream(void)
 	stream = trace_kernel_create_stream("stream1", 0);
 	ok(stream != NULL, "Create kernel stream");
 
+	if (!stream) {
+		skip(1, "Stream is null");
+		return;
+	}
+
 	ok(stream->fd == -1 &&
 	   stream->state == 0,
 	   "Validate kernel stream");
-- 
2.7.4



More information about the lttng-dev mailing list