From 29a13e49f1a33c6fed98bda4f5a83ddc5da4c398 Mon Sep 17 00:00:00 2001 From: jrd Date: Wed, 29 Jul 2026 00:57:15 +0000 Subject: [PATCH 1/2] Add MathUtils::InRange (backport util.h portion of #3741, #3812) release/3_12 needs MathUtils::InRange for the #3810 bounds-check backport, but #3741 introduced it as part of a much larger server chat-handling refactor (new CServer::SendChatTextToConChannel / SendChatTextToAllConChannels methods) that this branch does not have and is out of scope for a bug-fix backport. This squashes just the src/util.h hunks from the six main commits that shaped MathUtils::InRange into its current form, in order, omitting every hunk outside util.h: 562d6c66 Refactor server chat handling by extracting methods. Added range check method to MathUtils (#3741) 4f9a532a Clarify comment (#3741) 6d305cb7 Check for half open interval in MathUtils::InRange (#3812) 65513e5b Update src/util.h (#3812) fe98b1ad Fix style (#3812) Result is byte-for-byte identical to MathUtils::InRange on main. --- src/util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.h b/src/util.h index b083cd42a5..026aa6e768 100644 --- a/src/util.h +++ b/src/util.h @@ -1222,6 +1222,13 @@ class MathUtils return powf ( 10.0f, ( fInValueRange0_1 - 1.0f ) * AUD_MIX_FADER_RANGE_DB / 20.0f ); } } + + // Returns true if value is in [lower, upper) (inclusive lower, exclusive upper). + template + static inline bool InRange ( T value, T lower /* inclusive */, T upper /* exclusive */ ) + { + return value >= lower && value < upper; + } }; /******************************************************************************\ From f0180425a0d394f7747664bc24179923f5a194e0 Mon Sep 17 00:00:00 2001 From: ann0see <20726856+ann0see@users.noreply.github.com> Date: Mon, 20 Jul 2026 14:35:49 +0200 Subject: [PATCH 2/2] Add bounds check iChanID before array access Switch bounds check to use MathUtils Fix channel ID range check in audiomixerboard (cherry picked from commit 562cfd84db9a37b8e9bfb03234ffc7a648ce74f7) --- src/audiomixerboard.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index 20c823bf2f..08c45b2310 100644 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -1349,9 +1349,12 @@ void CAudioMixerBoard::ApplyNewConClientList ( CVector& vecChanInf for ( size_t iFader = 0; iFader < iNumConnectedClients; iFader++ ) { - // ideally "iChanID" in CChannelInfo would be size_t if it can never be INVALID_INDEX - // as assumed here - iFaderNumber[vecChanInfo[iFader].iChanID] = static_cast ( iFader ); + const int iChanID = vecChanInfo[iFader].iChanID; + + if ( MathUtils::InRange ( iChanID, 0, MAX_NUM_CHANNELS ) ) + { + iFaderNumber[iChanID] = static_cast ( iFader ); + } } // Hide all unused faders and initialize used ones