From: Jérémie Galarneau Date: Tue, 15 Mar 2022 21:13:03 +0000 (-0400) Subject: Clean-up: sessiond-comm: out of bounds access warning X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=62e6775c1485031cd086d8bc099f19265af44e56 Clean-up: sessiond-comm: out of bounds access warning 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 Change-Id: I260185f2baf085ca4486ce3b13696ee5fa55938a --- diff --git a/src/common/event.cpp b/src/common/event.cpp index 601c6ac1f..9cef3e9b9 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -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; diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index f80c3e7c8..e327e014c 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -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.