]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
test/mds: fix stack-use-after-scope in unittest_mds_quiesce_db 66851/head
authorKefu Chai <k.chai@proxmox.com>
Fri, 9 Jan 2026 01:32:49 +0000 (09:32 +0800)
committerKefu Chai <k.chai@proxmox.com>
Fri, 9 Jan 2026 04:04:15 +0000 (12:04 +0800)
commit4f33bcbb3e1eee2876c9634196761f22e1b331dd
tree5fb26757a18717c9cce49fe4dd102918c838aa26
parent533f2c7f72f9f3eac10fc4b43b68992e61e01b50
test/mds: fix stack-use-after-scope in unittest_mds_quiesce_db

The cartesian_apply() function in TestQuiesceDb.cc had a stack-use-
after-scope issue detected by ASan. The problem was that the lambda
function at line 513 had an implicit return type deduction that
returned a value instead of a reference:

  auto f = [&q](const auto &args) {
    q = div(q.quot, args.size());
    return args.at(q.rem);  // Returns V instead of V const&
  };

Even though args.at(q.rem) returns a const reference to an element
in the array, the lambda's auto return type deduction caused it to
return by value. This meant the tuple at line 518:

  auto apply_tuple = std::tuple<V const &...> { f(array_args)... };

was storing references to temporary values that went out of scope
immediately after tuple construction. When std::apply() later tried
to use these references, it accessed freed stack memory.

Fix by explicitly specifying the lambda's return type as decltype(auto)
to preserve the reference semantics:

  auto f = [&q](const auto &args) -> decltype(auto) {
    q = div(q.quot, args.size());
    return args.at(q.rem);  // Now returns V const& as intended
  };

This ensures the lambda returns a reference to the array element,
which remains valid for the lifetime of array_args (the entire scope
of cartesian_apply()). This preserves the original optimization of
avoiding copies while fixing the use-after-scope issue.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/test/mds/TestQuiesceDb.cc