Repository navigation
Conversation
EvaluateClientIDMes accepted any 1-byte value (0-255). An ID >= MAX_NUM_CHANNELS made FindClientChannel return INVALID_INDEX, and with --mutemyown the client then called SetRemoteChanGain(-1), writing outside clientChannels[]. Drop the message if the ID is out of range, and assert the index in SetRemoteChanGain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe client gain update now asserts that its channel ID is within the valid range before accessing the channel array. The protocol message evaluator rejects IDs outside that range before emitting ChangesClient ID validation
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~5 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The protocol rejects out-of-range client IDs before dispatch, and the inspected callers provide bounded indices. No actionable merge-blocking risk introduced by this change remains. Pre-merge checks |
|
|
|
||
| QMutexLocker locker ( &MutexGainOrPan ); | ||
|
|
||
| CClientChannel* clientChan = &clientChannels[iId]; |
There was a problem hiding this comment.
So Q_ASSERT compiles to nothing in released code. This line, then, potentially returns a pointer to ... whatever "address" lies at iId * index size from clientChannels?
There was a problem hiding this comment.
The point being, the moment the reader sees "Q_ASSERT" without a comment, they have to work out for themselves what the author intended and the provenance of the data.
Either the protocol handler code -- the exposed point of injection -- is sufficient, or it's not. This feels like visual clutter.
There was a problem hiding this comment.
but what if some future user of SetRemoteChanGain forgets to validate the range of iId?
There was a problem hiding this comment.
or maybe this function should return an true/false. i.e. return false when iId violates range.
There was a problem hiding this comment.
but what if some future user of SetRemoteChanGain forgets to validate the range of iId?
Q_ASSERT doesn't do anything in release code. There is no code generated. It is not a safety net.
or maybe this function should return an true/false. i.e. return false when iId violates range.
Maybe it should just be a lambda on the connection from the protocol signal - which is validated. Unless it's exposed to other callers, in which case, yes, it should validate the parameter as it doesn't necessarily know what the caller is.
The return true/false is only any good when you know the caller will understand it. So in this case, I'd prefer an error being thrown -- it's a "This should never happen" case. (Effectively an "assert" is saying "you should never violate this"; Q_ASSERT does that in debug builds and that's fine if we had test coverage which we knew would catch every case. But we don't.)
There was a problem hiding this comment.
@JohnZ622 as background: https://stackoverflow.com/a/2174550
There was a problem hiding this comment.
🤖 AI: Every client protocol message runs through one queued slot whose only exception sink is the CGenErr catch around exec(), so a thrown guard here exits the client: built at 4c0dbf23, the proposed throw turns a server's out-of-range CLIENT_ID into exit ( 1 ) where a return drops it.
There was a problem hiding this comment.
Maybe it should just be a lambda on the connection from the protocol signal - which is validated.
What do you mean a lambda on the connection from the protocol signal?
The return true/false is only any good when you know the caller will understand it. So in this case, I'd prefer an error being thrown
Should I throw CGenErr?
| { | ||
| // just update the new value for sending later; | ||
| // will compare with oldGain when the timer fires | ||
| clientChan->newGain = fGain; |
There was a problem hiding this comment.
Write to some unknown location.
| // will compare with oldGain when the timer fires | ||
| clientChan->newGain = fGain; | ||
|
|
||
| // update range of channel IDs to check in the timer |
There was a problem hiding this comment.
Store some potentially invalid data as if it were reliable.
Short description of changes
EvaluateClientIDMes accepted any 1-byte value (0-255). An ID >= MAX_NUM_CHANNELS made FindClientChannel return INVALID_INDEX, and with --mutemyown the client then called SetRemoteChanGain(-1), writing outside clientChannels[].
The behavior now is to drop the message if the ID is out of range, and assert the index in SetRemoteChanGain.
CHANGELOG:
Fixed: CClient::OnClientIDReceived could read array OOB if ID exceeds MAX_NUM_CHANNELS
Context: Fixes an issue?
Fixes: Issue #3926
Does this change need documentation? What needs to be documented and how?
No.
Status of this Pull Request
Ready to merge.
What is missing until this pull request can be merged?
Ready to merge