From: Francis Deslauriers Date: Fri, 28 May 2021 20:06:09 +0000 (-0400) Subject: Fix: appending unallocated data from beyond exclusion entries X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=1085f5eafd7f240089e410d94cb3f8b9fa19a090 Fix: appending unallocated data from beyond exclusion entries Issue ===== If an exclusion string is smaller than the `LTTNG_SYMBOL_NAME_LEN` integer, the `lttng_dynamic_buffer_append()` call will append unallocated data to the buffer. Fix === Use the `exclusion_len` value to copy the actual exclusion and pad the remaining bytes with zeros. Signed-off-by: Francis Deslauriers Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau Change-Id: I04c6681c28e82de29791541eb490158db9e503d0 --- diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index d9805e222..7ad1fe132 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -1204,7 +1204,7 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, for (i = 0; i < exclusion_count; i++) { size_t exclusion_len; - exclusion_len = lttng_strnlen(*(exclusion_list + i), + exclusion_len = lttng_strnlen(exclusion_list[i], LTTNG_SYMBOL_NAME_LEN); if (exclusion_len == LTTNG_SYMBOL_NAME_LEN) { /* Exclusion is not NULL-terminated. */ @@ -1213,7 +1213,17 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, } ret = lttng_dynamic_buffer_append(&payload.buffer, - *(exclusion_list + i), LTTNG_SYMBOL_NAME_LEN); + exclusion_list[i], exclusion_len); + if (ret) { + goto mem_error; + } + + /* + * Padding the rest of the entry with zeros. Every exclusion + * entries take LTTNG_SYMBOL_NAME_LEN bytes in the buffer. + */ + ret = lttng_dynamic_buffer_set_size(&payload.buffer, + LTTNG_SYMBOL_NAME_LEN * (i + 1)); if (ret) { goto mem_error; }