Repository navigation
Description
Describe the bug
INVALID_INDEX might not be checked everywhere correctly. AI found out that there could be an out of bounds read possiblity in client.cpp if calling SetRemoteChanGain:
Lines 1020 to 1031 in 508f1f3
| // allocate and map client-side channel 0 | |
| int iChanID = FindClientChannel ( iServerChanID, true ); // should always return channel 0 | |
| // for headless mode we support to mute our own signal in the personal mix | |
| // (note that the check for headless is done in the main.cpp and must not | |
| // be checked here) | |
| if ( bMuteMeInPersonalMix ) | |
| { | |
| SetRemoteChanGain ( iChanID, 0, false ); | |
| } | |
To Reproduce
Not tested. Would probably need some server side trigger with invalid Channel ID.
Probably worth checking on the protocol level for invalid IDs.
Ox Alpha (GLM 5.3-Flash) suggested:
Guard the call site (minimal change):
if ( iChanID != INVALID_INDEX && bMuteMeInPersonalMix ) { ... }and/or reject invalid IDs in EvaluateClientIDMes; optionally add a defensive Q_ASSERT/range check in SetRemoteChanGain/SetRemoteChanPan mirroring OnControllerInFaderLevel (client.cpp:956). Related latent gap: OnControllerInPanValue (client.cpp:965-975) lacks the bounds check its fader sibling has.
Expected behavior
No crash
AI analysis
src/protocol.cpp:1046-1063(EvaluateClientIDMes) — validates only body size (1 byte); the ID value itself (0–255) is passed through unchecked.src/client.cpp:1010-1036(CClient::OnClientIDReceived):
int iChanID = FindClientChannel ( iServerChanID, true ); // should always return channel 0
...
if ( bMuteMeInPersonalMix )
{
SetRemoteChanGain ( iChanID, 0, false ); // iChanID can be INVALID_INDEX (-1)
}src/client.cpp:1833-1885(FindClientChannel) returnsINVALID_INDEX(-1) wheniServerChannelID < 0 || >= MAX_NUM_CHANNELSor when all 150 client channel slots are occupied.src/client.cpp:506-539(SetRemoteChanGain):&clientChannels[iId]with no bounds check →- timer inactive: OOB write at
client.cpp:535(clientChan->oldGain = clientChan->newGain = fGain;) plus OOB read ofiServerChannelIDfed toChannel.SetRemoteChanGain()(that callee is range-checked,channel.cpp:302); - timer active: OOB write at
client.cpp:522, andminGainOrPanId = -1causesOnTimerRemoteChanGainOrPan(client.cpp:546-548) to iterate from index −1 afterwards.
- timer inactive: OOB write at
clientChannelsis a fixedCClientChannel[150]member array (src/client.h:392).
Contrast with the correct pattern used 700 lines earlier: OnMuteStateHasChangedReceived checks if ( iChanID != INVALID_INDEX ) (client.cpp:340-346).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
mcfnord commentedon Aug 27, 2026
🤖 AI: Reproduced end-to-end under AddressSanitizer at
508f1f3d— confirmed. ACLIENT_IDwhose byte is ≥MAX_NUM_CHANNELSdrivesFindClientChanneltoINVALID_INDEX, andSetRemoteChanGain ( iChanID, 0, false )writes 4 bytes into theCClientChannelslot immediately before the array (client.cpp:535). ASan trace:ParseMessageBody→EvaluateClientIDMes(only the 1-byte size is checked) →OnClientIDReceived→ that write.Two refinements:
--mutemyownonly — the call is gated bybMuteMeInPersonalMix, which the GUI disables. Exposure is a headless--mutemyownclient on a hostile or buggy server; a normal server never assigns an ID ≥MAX_NUM_CHANNELS.clientChannels[MAX_NUM_CHANNELS]array the same input neither crashes nor trips ASan ([-1]hits adjacentCClientmembers); it surfaced only once that array was heap-allocated for redzones. So the effect is corruption, not a reliable crash.The sibling
OnControllerInPanValuegap reads latent-only — its only emitters (MIDI mapping, JSON-RPC fader) already bound the channel index.ann0see commentedon Aug 27, 2026
Yep. GLM also time me that it's only happening if mutemyown is set. It's definitely not severe and easy to fix.
JohnZ622 commentedon Oct 8, 2026
Reproduced on main (bad66c0).
Setup: debug build, -fsanitize=address,bounds-strict (g++ 11, Qt 5.15.3), jackd -d dummy, stock server ./Jamulus -s -n -p 22150.
Client: gdb --args ./Jamulus -n --mutemyown -c localhost:22150. Break in EvaluateClientIDMes before the emit, then set var iCurID = 200 and continue.
Full trace
Build: g++ 11, Qt 5.15.3, CONFIG+=debug, -fsanitize=address,**bounds-strict**. Server: stock main (bad66c0) `-s -n -p 22150`, jackd -d dummy.main (bad66c0):
gdb --args ./Jamulus -n --mutemyown -c localhost:22150, iCurID set to 200 in EvaluateClientIDMesfix branch: same steps, 20 s timeout. OnClientIDReceived / SetRemoteChanGain breakpoints never hit, no sanitizer output
fix branch: normal connect (no value change). Connects as channel 0, SetRemoteChanGain(0) runs, no sanitizer output
Notes:
Fix:
https://github.com/JohnZ622/jamulus/tree/fix/client-id-bounds-check
I have a fix (+7 lines): EvaluateClientIDMes drops an ID if it is >= MAX_NUM_CHANNELS, and SetRemoteChanGain does a Q_ASSERT on the index.
Test behavior with fix:
ID changed to 200: the message is dropped, OnClientIDReceived is never called, and there's no sanitizer output.
Normal connect: the client gets channel 0, SetRemoteChanGain(0) runs, and there's no sanitizer output.
🤖 Used AI: Claude Opus 5.5, Claude Code
ann0see commentedon Oct 9, 2026
Feel free to open a PR. I don't think a QAssert is needed.
softins commentedon Nov 29, 2026
As mentioned originally by AI in the description, the only thing required is in
CClient::OnClientIDReceived()to check thatFindClientChannel()returns a real channel ID, notINVALID_INDEX. It would only do the latter if it received a bad message from a buggy or hostile server.SetRemoteChanGain()is defined as expecting a client-side channel ID within the expected range.FindClientChannel()returns either such a channel ID, or elseINVALID_INDEX. Other calls toFindClientChannel()do check for that condition, it is onlyCClient::OnClientIDReceived()that forgets to do so.The other calls to
SetRemoteChanGain()already give it a validated ID:CClientDlg::OnChangeChanGain()the ID comes directly from the fader index.CClient::OnControllerInFaderLevel(), the ID comes from a MIDI message, and is validated in that function before passing it toSetRemoteChanGain().There is no need to check the range of the ID in the protocol handler, as #3970 does, since the received ID is only used as an input to
FindClientChannel(), which itself validates the range of the ID, and returnsINVALID_INDEXif outside.