Fix null dereference in scheduler tick processing - #4571
Merged
Conversation
In trainprogram::scheduler(), bluetoothManager->device()->odometer() is called unconditionally at line 869. The null guard at line 626 does NOT protect this call — it enters an if-block that handles the 'not ready' case (Zwift API, OCR, etc.) but then falls through to line 869 regardless. If the device disconnects or is null at this point, the code crashes with a null pointer dereference. Fix: Add explicit null guard for both bluetoothManager and device() before the odometer() call. This ensures the scheduler exits safely if the device is unavailable.
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix null dereference in scheduler path
Problem
In
trainprogram.cpp:869,odometer()is called unconditionally:This occurs before the null-guard at line 626, creating a TOCTOU race condition:
If the device disconnects between these operations, the code crashes.
Root Cause
Method
timeRateFromGPX()callsbluetoothManager->device()->odometer()without checking if device is null (TOCTOU race).Solution
Add a null guard before the odometer() call to prevent crash under race conditions.
Changes
trainprogram.cpp:869before device access