ctf: grow stored_values array when necessary
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 17 Oct 2023 19:33:37 +0000 (15:33 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 20 Oct 2023 23:29:14 +0000 (19:29 -0400)
commit839df1da87b7bdaac5ebfd4e798ea769a94843b2
tree59cb73b185bf4269c4a17ae76b83fced617ad053
parent89ec984ed8142a2cd79603e8d7b26544fc17d2a7
ctf: grow stored_values array when necessary

The CTF message iterator accesses the `stored_values` array out of
bounds in the following situation:

 - In the context of a src.ctf.lttng-live source, a ctf_trace_class gets
   created from some metadata.
 - At this point, ctf_trace_class->stored_value_count indicates that a
   certain number of stored values are necessary given the metadata
   parsed up to now.
 - The message iterators are created with `stored_values` arrays of that
   size.
 - The source receives more metadata, which requires more stored
   values.
 - The message iterator reads some event described by the new metadata,
   that requires the use of a stored value.
 - Since the stored value arrays have not been resized to reflect the
   necessary number of stored value considering the new metadata, the
   message iterator tries to store a value past the end of the array.

Fix this by ensuring the `stored_values` array is large enough before
storing a value in it.

Add a test with a hand-crafted trace that replicates the scenario
described in the simplest manner possible:

 - send a bit of metadata
 - send a bit of data that uses that metadata
 - send a bit more metadata (that requires a new stored value)
 - send a bit of data that uses that new metadata

Without the fix, we get (when babeltrace is built in debug mode):

    (╯°□°)╯︵ ┻━┻  /home/smarchi/src/babeltrace/src/plugins/ctf/common/msg-iter/msg-iter.cpp:1865: bfcr_unsigned_int_cb(): Assertion `(uint64_t) int_fc->storing_index < msg_it->stored_values->len` failed.

... showing the out of bounds array access.

Change-Id: I78e3ca57ac6cae1959425df3c8ffdbfeb534f348
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10866
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/common/msg-iter/msg-iter.cpp
tests/data/ctf-traces/live/stored_values.mctf [new file with mode: 0644]
tests/data/plugins/src.ctf.lttng-live/stored_values.expect [new file with mode: 0644]
tests/data/plugins/src.ctf.lttng-live/stored_values.json [new file with mode: 0644]
tests/plugins/src.ctf.lttng-live/test_live
This page took 0.024856 seconds and 4 git commands to generate.