Clean-up: tests: silence bogus warning
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 16 Mar 2022 21:55:45 +0000 (17:55 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 16 Mar 2022 21:55:48 +0000 (17:55 -0400)
1486757 Buffer not null terminated
If the buffer is treated as a null terminated string in later operations, a buffer overflow or over-read may occur.

In test_create_ust_event_exclusion(): The string buffer may not have a null terminator if the source string's length is equal to the buffer size (CWE-170)

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0c3fd6c9d591e1c67d8b80bf12825bb0d1520a65

tests/unit/test_ust_data.cpp

index 04aa8c83eb994c7dc7c7fc29ddec466391047705..e62f6b571e5db99e34a893575633506815446812 100644 (file)
@@ -143,6 +143,7 @@ static void test_create_ust_event(void)
 
 static void test_create_ust_event_exclusion(void)
 {
+       int copy_ret;
        enum lttng_error_code ret;
        struct ltt_ust_event *event;
        struct lttng_event ev;
@@ -206,16 +207,24 @@ static void test_create_ust_event_exclusion(void)
         */
 
        exclusion->count = exclusion_count;
-       strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0),
-               get_random_string(), LTTNG_SYMBOL_NAME_LEN - 1);
-       strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1),
-               get_random_string(), LTTNG_SYMBOL_NAME_LEN - 1);
+       copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0),
+                       get_random_string(),
+                       sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0)));
+       LTTNG_ASSERT(copy_ret == 0);
+       copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1),
+                       get_random_string(),
+                       sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1)));
+       LTTNG_ASSERT(copy_ret == 0);
 
        exclusion_copy->count = exclusion_count;
-       strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0),
-               LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), LTTNG_SYMBOL_NAME_LEN);
-       strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1),
-               LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), LTTNG_SYMBOL_NAME_LEN);
+       copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0),
+                       LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0),
+                       sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0)));
+       LTTNG_ASSERT(copy_ret == 0);
+       copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1),
+                       LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1),
+                       sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1)));
+       LTTNG_ASSERT(copy_ret == 0);
 
        ret = trace_ust_create_event(&ev, NULL, NULL, exclusion, false, &event);
        exclusion = NULL;
This page took 0.025683 seconds and 4 git commands to generate.