You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tunes.cpp - Conditional jump on uninitialized variables in Tunes::get_next_note(unsigned&, unsigned&, unsigned&, uint8_t&)
In the four-parameter overload of Tunes::get_next_note, when the internal 3-parameter version returns a non-Continue status, the out-parameters frequency and duration remain uninitialized. Immediately afterward, the code does
if (frequency == 0 || duration == 0) { … }
thus performing a conditional jump on uninitialized stack memory.
To Reproduce
Note: simply replaying the same payload does not reliably trigger the issue due to nondeterministic stack contents.
Launch the PX4 SITL executable under any runtime monitor or debugger.
You will see that tunes.cpp’s four-parameter get_next_note() can perform a conditional on uninitialized variables.
Expected behavior
when the bug occurs, the three-parameter get_next_note(frequency, duration, silence) call returns a non-Continue status without ever writing to frequency or duration, and then the very next if (frequency == 0 || duration == 0) reads those uninitialized values, causing an unpredictable branch that may leave volume set to garbage or zero before the function returns Stop. As a result, even though the tune should simply end, you can get a stray or incorrect tune message (or volume) at the end due to that undefined read.
Screenshot / Media
No response
Flight Log
No response
Software Version
pxh> ver all
HW arch: PX4_SITL
PX4 git-hash: 5509061
PX4 version: 1.16.0 80 (17825920)
PX4 git-branch: main
OS: Linux
OS version: Release 5.15.133 (84903423)
Build datetime: Apr 2 2025 14:55:21
Build uri: localhost
Build variant: default
Toolchain: GNU GCC, 9.3.0
PX4GUID: 100655d4d9534954414c44494e4f303030
UNKNOWN MCU
Flight controller
SITL
Vehicle type
None
How are the different components wired up (including port information)
No response
Additional context
Solution (Add an early check for ret != Continue that zeroes all four output parameters and returns immediately, preventing any uninitialized reads in the subsequent volume check.):
Describe the bug
tunes.cpp
- Conditional jump on uninitialized variables inTunes::get_next_note(unsigned&, unsigned&, unsigned&, uint8_t&)
In the four-parameter overload of Tunes::get_next_note, when the internal 3-parameter version returns a non-Continue status, the out-parameters frequency and duration remain uninitialized. Immediately afterward, the code does
thus performing a conditional jump on uninitialized stack memory.
To Reproduce
Note: simply replaying the same payload does not reliably trigger the issue due to nondeterministic stack contents.
Expected behavior
when the bug occurs, the three-parameter
get_next_note(frequency, duration, silence)
call returns a non-Continue status without ever writing to frequency or duration, and then the very nextif (frequency == 0 || duration == 0)
reads those uninitialized values, causing an unpredictable branch that may leave volume set to garbage or zero before the function returns Stop. As a result, even though the tune should simply end, you can get a stray or incorrect tune message (or volume) at the end due to that undefined read.Screenshot / Media
No response
Flight Log
No response
Software Version
pxh> ver all
HW arch: PX4_SITL
PX4 git-hash: 5509061
PX4 version: 1.16.0 80 (17825920)
PX4 git-branch: main
OS: Linux
OS version: Release 5.15.133 (84903423)
Build datetime: Apr 2 2025 14:55:21
Build uri: localhost
Build variant: default
Toolchain: GNU GCC, 9.3.0
PX4GUID: 100655d4d9534954414c44494e4f303030
UNKNOWN MCU
Flight controller
SITL
Vehicle type
None
How are the different components wired up (including port information)
No response
Additional context
Solution (Add an early check for ret != Continue that zeroes all four output parameters and returns immediately, preventing any uninitialized reads in the subsequent volume check.):
File: https://github.com/PX4/PX4-Autopilot/blob/main/src/lib/tunes/tunes.cpp
Original code:
The text was updated successfully, but these errors were encountered: