mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-07-26 03:54:30 -04:00
PlutoSDR: Guard against null buddy shared pointers | Fix #2779
Add defensive null checks before dereferencing DeviceAPI::getBuddySharedPtr() in the PlutoSDR input and output plugins. DeviceAPI initializes the buddy shared pointer to nullptr, so a buddy may exist before its shared state has been attached. This could result in null pointer dereferences during device initialization, buddy thread suspend/resume, or settings application. Changes include: - Validate buddy shared pointer in openDevice() and fail gracefully if absent. - Guard suspendBuddies() and resumeBuddies() against null shared pointers. - Skip buddies without shared state during applySettings() while logging a warning. - Prevent dereferencing null buddy shared pointers when restarting buddy threads. These changes improve robustness during PlutoSDR buddy initialization and avoid crashes caused by partially initialized buddy relationships. Signed-off-by: Robin Getz <rgetz503@gmail.com>
This commit is contained in:
@@ -282,6 +282,11 @@ bool PlutoSDRInput::openDevice()
|
||||
|
||||
DeviceAPI *sinkBuddy = m_deviceAPI->getSinkBuddies()[0];
|
||||
DevicePlutoSDRShared* buddySharedPtr = (DevicePlutoSDRShared*) sinkBuddy->getBuddySharedPtr();
|
||||
if (!buddySharedPtr)
|
||||
{
|
||||
qCritical("PlutoSDRInput::openDevice: Tx buddy has no shared data");
|
||||
return false;
|
||||
}
|
||||
m_deviceShared.m_deviceParams = buddySharedPtr->m_deviceParams;
|
||||
|
||||
if (m_deviceShared.m_deviceParams == 0)
|
||||
@@ -379,7 +384,7 @@ void PlutoSDRInput::suspendBuddies()
|
||||
DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[i];
|
||||
DevicePlutoSDRShared *buddyShared = (DevicePlutoSDRShared *) buddy->getBuddySharedPtr();
|
||||
|
||||
if (buddyShared->m_thread) {
|
||||
if (buddyShared && buddyShared->m_thread) {
|
||||
buddyShared->m_thread->stopWork();
|
||||
}
|
||||
}
|
||||
@@ -394,7 +399,7 @@ void PlutoSDRInput::resumeBuddies()
|
||||
DeviceAPI *buddy = m_deviceAPI->getSinkBuddies()[i];
|
||||
DevicePlutoSDRShared *buddyShared = (DevicePlutoSDRShared *) buddy->getBuddySharedPtr();
|
||||
|
||||
if (buddyShared->m_thread) {
|
||||
if (buddyShared && buddyShared->m_thread) {
|
||||
buddyShared->m_thread->startWork();
|
||||
}
|
||||
}
|
||||
@@ -444,6 +449,12 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, const Q
|
||||
{
|
||||
DevicePlutoSDRShared *buddySharedPtr = (DevicePlutoSDRShared *) (*itSink)->getBuddySharedPtr();
|
||||
|
||||
if (!buddySharedPtr)
|
||||
{
|
||||
qWarning("PlutoSDRInput::applySettings: sink buddy has no shared data");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buddySharedPtr->m_thread) {
|
||||
buddySharedPtr->m_thread->stopWork();
|
||||
buddySharedPtr->m_threadWasRunning = true;
|
||||
@@ -624,7 +635,7 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, const Q
|
||||
{
|
||||
DevicePlutoSDRShared *buddySharedPtr = (DevicePlutoSDRShared *) (*itSink)->getBuddySharedPtr();
|
||||
|
||||
if (buddySharedPtr->m_threadWasRunning) {
|
||||
if (buddySharedPtr && buddySharedPtr->m_threadWasRunning) {
|
||||
buddySharedPtr->m_thread->startWork();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user