From cb78c3bf2c690da04ec654e2cacc1e7a064f8da9 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Mon, 6 Mar 2023 22:59:51 -0300 Subject: [PATCH] replica: Fix undefined behavior in table::generate_and_propagate_view_updates() Undefined behavior because the evaluation order is undefined. With GCC, where evaluation is right-to-left, schema will be moved once it's forwarded to make_flat_mutation_reader_from_mutations_v2(). The consequence is that memory tracking of mutation_fragment_v2 (for tracking only permit used by view update), which uses the schema, can be incorrect. However, it's more likely that Scylla will crash when estimating memory usage for row, which access schema column information using schema::column_at(), which in turn asserts that the requested column does really exist. Fixes #13093. Signed-off-by: Raphael S. Carvalho Closes #13092 (cherry picked from commit 3fae46203d3105373e0bf3a4ccd771edee2bc0d7) --- replica/table.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/replica/table.cc b/replica/table.cc index f7e2fb97b5..6b8aaf80cd 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -1776,10 +1776,11 @@ future<> table::generate_and_propagate_view_updates(const schema_ptr& base, tracing::trace_state_ptr tr_state, gc_clock::time_point now) const { auto base_token = m.token(); + auto m_schema = m.schema(); db::view::view_update_builder builder = co_await db::view::make_view_update_builder( base, std::move(views), - make_flat_mutation_reader_from_mutations(m.schema(), std::move(permit), {std::move(m)}), + make_flat_mutation_reader_from_mutations(std::move(m_schema), std::move(permit), {std::move(m)}), std::move(existings), now);