Skip to content

Commit bba344b

Browse files
committed
fix: stack corruption in MultiCommandSquasher (#5697)
Fixes #5690 The problem: we accessed the caller stack variables (max_exec_cycles) in MultiCommandSquasher::ExecuteSquashed. The access was done after the call to `bc.Dec()`, which unblocks ExecuteSquashed. As a result, the callback function that was still running could corrupt memory contents of some other variable as ExecuteSquashed could exit by that time. In addition, harden checks in stream_family.cc in StreamAppendItem. Finally, we update helio which fixes #5693 Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent 91a23c8 commit bba344b

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/server/multi_command_squasher.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,15 @@ bool MultiCommandSquasher::ExecuteSquashed(facade::RedisReplyBuilder* rb) {
296296
stats_.yields++;
297297
}
298298
this->SquashedHopCb(EngineShard::tlocal(), rb->GetRespVersion());
299-
bc->Dec();
300299
uint64_t exec_time = CycleClock::Now() - start;
301300
current = max_exec_cycles.load(memory_order_relaxed);
302301
while (exec_time > current) {
303302
if (max_exec_cycles.compare_exchange_weak(current, exec_time, memory_order_relaxed,
304303
memory_order_relaxed))
305304
break;
306305
}
306+
307+
bc->Dec(); // Release barrier: Must be the last one in the callback.
307308
};
308309
for (unsigned i = 0; i < sharded_.size(); ++i) {
309310
if (!sharded_[i].dispatched.empty())

src/server/stream_family.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ int StreamAppendItem(stream* s, CmdArgList fields, uint64_t now_ms, streamID* ad
432432
/* Get a reference to the tail node listpack. */
433433
lp = (uint8_t*)ri.data;
434434
lp_bytes = lpBytes(lp);
435+
CHECK_GT(lp_bytes, 0U);
435436
}
436437
raxStop(&ri);
437438

0 commit comments

Comments
 (0)