Cash Budget Product Launch

Cover Page For Ayurvedic Products

premium photo a pilot and copilot in the cockpit preparing for

:
Credit Card Folser Template
author
crichard
committed
[Fix][Crash] Serialize timer access with a mutex to close UAF race
The client_impl ping/pong timer fields (m_send_timer, m_timeout_timer, m_reconn_timer) are mutated from two threads: the network thread (on_close -> clear_timers, on_pong) and the SAL timer worker thread (timeout_send, timeout_wait). Upstream socket.io ran all timers on the single asio io_service thread, so this was safe; the SAL port fires timer callbacks on its own worker thread and introduced the data race. The previous release()-based reset_timer did not fully close the window: calling release() concurrently on the same smart pointer is itself a data race, so two threads could observe the same raw pointer (or a torn read) and cancel/delete a timer that was already freed. The result was an EXC_BAD_ACCESS on reused heap memory inside TimerManager::removeTimer, reached via on_close -> clear_timers -> reset_timer -> timer::cancel. Add a dedicated m_timer_mutex and route every access to the three timer fields through reset_timer / update_timer / clear_timers under that lock, so cancel+destroy and reassignment are serialized and can no longer run on a freed timer. The mutex is recursive because clear_timers and update_timer hold it while calling reset_timer (update_timer must keep the reset and the reassignment atomic), and a plain std::mutex would self-deadlock on that re-entry. unique_ptr ownership is kept. Change-Id: I0852197732d12faf7e0ccd73131471c3aeaa5cb0
1 parent Square Instagram Post Look On A Story commit 0d930c5

Premium photo a pilot and copilot in the cockpit preparing for 2 files changed Product Facebook Post Sample

Lines changed: 10 additions & 6 deletions

Create Your Own Business Cards Cover Page For Ayurvedic Products

src/internal/sio_client_impl.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,18 @@ namespace sio
626626
void client_impl::clear_timers()
627627
{
628628
SAL_FUNC_INFO("clear timers");
629-
std::error_code ec;
629+
std::lock_guard<std::recursive_mutex> lk(m_timer_mutex);
630630
reset_timer(m_timeout_timer);
631631
reset_timer(m_send_timer);
632632
}
633633

634634
void client_impl::reset_timer(TIMER &timer) {
635-
// Atomically take ownership of the timer pointer before operating on
636-
// it. Without this, a concurrent caller (e.g. another reset_timer /
637-
// update_timer on the same field, or a TimerManager callback racing
638-
// with on_close's clear_timers) could pass the null check while we
639-
// are mid-destroy and crash dereferencing a freed timer.
635+
// m_timer_mutex is recursive so callers that already hold it
636+
// (clear_timers, update_timer) can re-enter this helper. Take
637+
// ownership of the timer pointer before operating on it: with the lock
638+
// held this can't race a concurrent reset/update on the same field, so
639+
// cancel+destroy run exactly once and never on freed memory.
640+
std::lock_guard<std::recursive_mutex> lk(m_timer_mutex);
640641
if (auto* t = timer.release())
641642
{
642643
t->cancel();
@@ -662,6 +663,7 @@ namespace sio
662663
void client_impl::update_timer(TIMER &timer, int timeout, func_ptr name)
663664
{
664665
#ifdef _SAL_TIME_H
666+
std::lock_guard<std::recursive_mutex> lk(m_timer_mutex);
665667
reset_timer(timer);
666668
timer.reset(SAL::timer_cb::set_timer(timeout, std::bind(name, this, std::placeholders::_1)));
667669
#else

src/internal/sio_client_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ namespace sio
206206
typedef void (sio::client_impl::*func_ptr)(const std::error_code&) ;
207207
void update_timer(TIMER &timer, int timeout, func_ptr name);
208208
void reset_timer(TIMER &timer);
209+
std::recursive_mutex m_timer_mutex;
209210
TIMER m_send_timer;
210211
TIMER m_timeout_timer;
211212
TIMER m_reconn_timer;
@@ -239,6 +240,7 @@ namespace sio
239240

240241
friend class sio::client;
241242
friend class sio::socket;
243+
242244
};
243245
}
244246
#endif // SIO_CLIENT_IMPL_H

Product Story Template Cover Page For Ayurvedic Products

Comments
 (0)