From ebe4c684d397992e70455847890cc2fe13d2b79d Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Nov 2019 15:22:39 -0500 Subject: [PATCH] ctf: assert that msg iter and medium seek offset is valid I don't think there is ever a valid situation for `offset` to have an invalid value in ctf_msg_iter_seek or medop_seek. If the user of the iterator (e.g. fs.c) thinks it's cool enough to seek, it should know about the underlying medium it used to create the msg iter and make sure not to seek at an invalid position. This allows removing the INVAL values in enum ctf_msg_iter_medium_status and enum ctf_msg_iter_status. Change-Id: I19d48fe751aebf21e60c5cbc16127919a5fa72f3 Signed-off-by: Simon Marchi --- src/plugins/ctf/common/msg-iter/msg-iter.c | 9 +-------- src/plugins/ctf/common/msg-iter/msg-iter.h | 10 ---------- src/plugins/ctf/fs-src/data-stream-file.c | 8 ++------ src/plugins/ctf/lttng-live/lttng-live.c | 2 -- 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.c b/src/plugins/ctf/common/msg-iter/msg-iter.c index a074aafe..0a16eed4 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.c +++ b/src/plugins/ctf/common/msg-iter/msg-iter.c @@ -3160,17 +3160,10 @@ enum ctf_msg_iter_status ctf_msg_iter_seek(struct ctf_msg_iter *msg_it, off_t offset) { enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK; - bt_self_component *self_comp = msg_it->self_comp; enum ctf_msg_iter_medium_status medium_status; BT_ASSERT(msg_it); - if (offset < 0) { - BT_COMP_LOGE_APPEND_CAUSE(self_comp, - "Cannot seek to negative offset: offset=%jd", - (intmax_t) offset); - status = CTF_MSG_ITER_STATUS_INVAL; - goto end; - } + BT_ASSERT(offset >= 0); if (!msg_it->medium.medops.seek) { status = CTF_MSG_ITER_STATUS_UNSUPPORTED; diff --git a/src/plugins/ctf/common/msg-iter/msg-iter.h b/src/plugins/ctf/common/msg-iter/msg-iter.h index 9fecf728..dd3b01d3 100644 --- a/src/plugins/ctf/common/msg-iter/msg-iter.h +++ b/src/plugins/ctf/common/msg-iter/msg-iter.h @@ -64,9 +64,6 @@ enum ctf_msg_iter_medium_status { /** Unsupported operation. */ CTF_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED = -3, - /** Invalid argument. */ - CTF_MSG_ITER_MEDIUM_STATUS_INVAL = -2, - /** General error. */ CTF_MSG_ITER_MEDIUM_STATUS_ERROR = -1, @@ -97,9 +94,6 @@ enum ctf_msg_iter_status { */ CTF_MSG_ITER_STATUS_AGAIN = CTF_MSG_ITER_MEDIUM_STATUS_AGAIN, - /** Invalid argument. */ - CTF_MSG_ITER_STATUS_INVAL = CTF_MSG_ITER_MEDIUM_STATUS_INVAL, - /** Unsupported operation. */ CTF_MSG_ITER_STATUS_UNSUPPORTED = CTF_MSG_ITER_MEDIUM_STATUS_UNSUPPORTED, @@ -350,8 +344,6 @@ const char *ctf_msg_iter_medium_status_string( return "EOF"; case CTF_MSG_ITER_MEDIUM_STATUS_AGAIN: return "AGAIN"; - case CTF_MSG_ITER_MEDIUM_STATUS_INVAL: - return "INVAL"; case CTF_MSG_ITER_MEDIUM_STATUS_ERROR: return "ERROR"; case CTF_MSG_ITER_MEDIUM_STATUS_OK: @@ -370,8 +362,6 @@ const char *ctf_msg_iter_status_string( return "EOF"; case CTF_MSG_ITER_STATUS_AGAIN: return "AGAIN"; - case CTF_MSG_ITER_STATUS_INVAL: - return "INVAL"; case CTF_MSG_ITER_STATUS_ERROR: return "ERROR"; case CTF_MSG_ITER_STATUS_OK: diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 9d9726fd..30da41a1 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -221,12 +221,8 @@ enum ctf_msg_iter_medium_status medop_seek(off_t offset, void *data) bt_self_component *self_comp = ds_file->self_comp; bt_logging_level log_level = ds_file->log_level; - if (offset < 0 || offset > file_size) { - BT_COMP_LOGE("Invalid medium seek request: offset=%jd, file-size=%jd", - (intmax_t) offset, (intmax_t) file_size); - status = CTF_MSG_ITER_MEDIUM_STATUS_INVAL; - goto end; - } + BT_ASSERT(offset >= 0); + BT_ASSERT(offset < file_size); /* If there is no current mapping, map the right file directly. */ if (!ds_file->mmap_addr) { diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index b8f3c8c2..2376d440 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -835,8 +835,6 @@ enum lttng_live_iterator_status lttng_live_iterator_next_handle_one_active_data_ */ ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE; break; - case CTF_MSG_ITER_STATUS_INVAL: - /* No argument provided by the user, so don't return INVAL. */ case CTF_MSG_ITER_STATUS_ERROR: default: ret = LTTNG_LIVE_ITERATOR_STATUS_ERROR; -- 2.34.1