Files
scylladb/test
Kamil Braun f42776aded raft: randomized_nemesis_test: fix potential use-after-free in basic_test
The test starts by waiting a certain number of ticks for the first node
to elect itself as a leader.

If this wait times out - i.e. the number of ticks passes before the node
manages to elect itself - the future associated with the task which checks
for the leader condition becomes discarded (it is passed to
`with_timeout`) and the task may keep using the `environment` (which it
has a reference to) even after the `environment` is destroyed.

Furthermore, the aforementioned task is a coroutine which uses lambda
captures in its body. Leaving `with_timeout` destroys the lambda object,
causing the coroutine to refer to no-longer-existing captures.

We fix the problems by:
- making `environment` `weakly_referencable` and checking if its alive
  before it's used inside the task,
- not capturing anything in the lambda but passing whatever's needed as
  function arguments (so these things get allocated inside the coroutine
  frame).
2021-06-14 16:54:38 +02:00
..