Clean-up: sessiond-comm: out of bounds access warning
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 15 Mar 2022 21:13:03 +0000 (17:13 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 16 Mar 2022 20:06:19 +0000 (16:06 -0400)
gcc 11.2 produces the two following warnings. In both case, setting an
array's dimension to zero is used to express a variable length array of
names that are LTTNG_SYMBOL_NAME_LEN bytes long. gcc doesn't know about
this and correctly points out that an access is taking place outside of
the array's bounds.

Omit the '0' dimension to work around this warning.

event.cpp: In function 'ssize_t lttng_event_create_from_payload(lttng_payload_view*, lttng_event**, lttng_event_exclusion**, char**, lttng_bytecode**)':
event.cpp:320:62: warning: array subscript i is outside array bounds of 'char [0][256]' [-Warray-bounds]
  320 |                 ret = lttng_strncpy(local_exclusions->names[i],
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~^
In file included from event.cpp:16:
../../src/common/sessiond-comm/sessiond-comm.h:569:14: note: while referencing 'lttng_event_exclusion::names'
  569 |         char names[0][LTTNG_SYMBOL_NAME_LEN];
      |              ^~~~~

event-rule/user-tracepoint.cpp: In function 'lttng_event_rule_generate_exclusions_status lttng_event_rule_user_tracepoint_generate_exclusions(const lttng_event_rule*, lttng_event_exclusion**)':
event-rule/user-tracepoint.cpp:383:61: warning: array subscript i is outside array bounds of 'char [0][256]' [-Warray-bounds]
  383 |                 copy_ret = lttng_strncpy(exclusions->names[i], exclusion_str,
      |                                          ~~~~~~~~~~~~~~~~~~~^
In file included from ../../src/common/runas.h:17,
                 from event-rule/user-tracepoint.cpp:17:
../../src/common/sessiond-comm/sessiond-comm.h:569:14: note: while referencing 'lttng_event_exclusion::names'
  569 |         char names[0][LTTNG_SYMBOL_NAME_LEN];
      |              ^~~~~

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

src/common/event.cpp
src/common/sessiond-comm/sessiond-comm.h

index 601c6ac1fa5f1d2de8c13790102b97c994ab820c..9cef3e9b9189829be10ca8eea0c300ac8be4fb4f 100644 (file)
@@ -319,8 +319,8 @@ static ssize_t lttng_event_exclusions_create_from_payload(
                        goto end;
                }
 
-               ret = lttng_strncpy(local_exclusions->names[i], string,
-                               sizeof(local_exclusions->names[i]));
+               ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(local_exclusions, i), string,
+                               sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(local_exclusions, i)));
                if (ret) {
                        ret = -1;
                        goto end;
index f80c3e7c8dbdfd867dce80f14bb5205535c9a087..e327e014c078a5c8fcee6c7c7f366bc29549b7da 100644 (file)
@@ -566,11 +566,11 @@ struct lttng_bytecode {
 struct lttng_event_exclusion {
        uint32_t count;
        char padding[LTTNG_EVENT_EXCLUSION_PADDING];
-       char names[0][LTTNG_SYMBOL_NAME_LEN];
+       char names[][LTTNG_SYMBOL_NAME_LEN];
 } LTTNG_PACKED;
 
 #define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) \
-       (&(_exclusion)->names[_i][0])
+       ((_exclusion)->names[_i])
 
 /*
  * Listing command header.
This page took 0.030077 seconds and 4 git commands to generate.