Skip to content

Commit d267206

Browse files
committed
Fix: Don't push invalid toc entry offset
1 parent bc07dbf commit d267206

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

contrib/plugins/bap-tracing/tracing.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {
199199

200200
static void plugin_exit(qemu_plugin_id_t id, void *udata) {
201201
g_rw_lock_writer_lock(&state.frame_buffer_lock);
202+
// Dump the rest of the frames.
202203
for (size_t i = 0; i < state.vcpus->len; ++i) {
203204
FrameBuffer *fbuf = g_ptr_array_index(state.frame_buffer, i);
204205
write_toc_entry(fbuf);
@@ -223,7 +224,14 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata) {
223224
uint64_t m = state.toc_entries_offsets->len;
224225
WRITE(m);
225226

226-
for (size_t i = 0; i < m; ++i) {
227+
for (size_t i = 0; i < m - 1; ++i) {
228+
// All except the last address in state.toc_entries_offsets
229+
// point to an entry. The last one points to nothing, because
230+
// we first push the offset and then push the frames later
231+
// when the buffer is full.
232+
// When we dumped the last frames above it lastly
233+
// pushed an additional offset.
234+
// This one we skip here with m - 1.
227235
uint64_t toc_entry_off =
228236
g_array_index(state.toc_entries_offsets, uint64_t, i);
229237
WRITE(toc_entry_off);

0 commit comments

Comments
 (0)