From 640a46fd3c8ebe3c14eb73f47ae6bbe22b19556f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Nov 2019 17:21:47 -0500 Subject: [PATCH] ctf: assert that request_sz in medium ops request_bytes is greater than 0 There's a check in medop_request_bytes to return OK if the passed request_sz is 0. I don't think that can ever happen, since that request_sz comes from the max_request_sz parameter when the iterator is created. It wouldn't make sense to pass 0. Change-Id: Ia2c8fb6e56195bcab607c39e366c6b58b3411f8b Signed-off-by: Simon Marchi --- src/plugins/ctf/common/msg-iter/msg-iter.c | 2 ++ src/plugins/ctf/fs-src/data-stream-file.c | 7 ++++--- src/plugins/ctf/lttng-live/data-stream.c | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index 782a5a34..9edc55c8 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -2837,6 +2837,8 @@ struct ctf_msg_iter *ctf_msg_iter_create( BT_ASSERT(tc); BT_ASSERT(medops.request_bytes); BT_ASSERT(medops.borrow_stream); + BT_ASSERT(max_request_sz > 0); + BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, log_level, self_comp, "Creating CTF plugin message iterator: " "trace-addr=%p, max-request-size=%zu, " diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 30da41a1..c4edcd32 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -143,9 +143,7 @@ enum ctf_msg_iter_medium_status medop_request_bytes( bt_self_component *self_comp = ds_file->self_comp; bt_logging_level log_level = ds_file->log_level; - if (request_sz == 0) { - goto end; - } + BT_ASSERT(request_sz > 0); /* * Check if we have at least one memory-mapped byte left. If we don't, @@ -174,9 +172,12 @@ enum ctf_msg_iter_medium_status medop_request_bytes( } } + BT_ASSERT(remaining_mmap_bytes(ds_file) > 0); *buffer_sz = MIN(remaining_mmap_bytes(ds_file), request_sz); + BT_ASSERT(ds_file->mmap_addr); *buffer_addr = ((uint8_t *) ds_file->mmap_addr) + ds_file->request_offset_in_mapping; + ds_file->request_offset_in_mapping += *buffer_sz; goto end; diff --git a/src/plugins/ctf/lttng-live/data-stream.c b/src/plugins/ctf/lttng-live/data-stream.c index 903cbf73..34356287 100644 --- a/src/plugins/ctf/lttng-live/data-stream.c +++ b/src/plugins/ctf/lttng-live/data-stream.c @@ -58,6 +58,8 @@ enum ctf_msg_iter_medium_status medop_request_bytes( uint64_t len_left; uint64_t read_len; + BT_ASSERT(request_sz); + if (stream->has_stream_hung_up) { status = CTF_MSG_ITER_MEDIUM_STATUS_EOF; goto end; -- 2.34.1