diff options
author | Chris Robinson <[email protected]> | 2023-05-01 03:43:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-05-01 03:43:25 -0700 |
commit | bd8c13d7883cb0a570f724885c7a55ad687dada6 (patch) | |
tree | 3cafbeece891e9187615ca1dc3b21fb3672ff385 | |
parent | 0e7d078b01e423e7973cc593046f9716d1ca8c0b (diff) |
Fix some debug message length limit checks
-rw-r--r-- | al/debug.cpp | 11 | ||||
-rw-r--r-- | alc/context.cpp | 11 |
2 files changed, 14 insertions, 8 deletions
diff --git a/al/debug.cpp b/al/debug.cpp index 26a69aff..66cbc622 100644 --- a/al/debug.cpp +++ b/al/debug.cpp @@ -134,15 +134,18 @@ FORCE_ALIGN void AL_APIENTRY alDebugMessageInsertSOFT(ALenum source, ALenum type if(!message) return context->setError(AL_INVALID_VALUE, "Null message pointer"); + /* MaxDebugMessageLength is the size including the null terminator, + * <length> does not include the null terminator. + */ if(length < 0) { size_t newlen{std::strlen(message)}; - if(newlen > MaxDebugMessageLength) UNLIKELY - return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu > %d)", newlen, - MaxDebugMessageLength); + if(newlen >= MaxDebugMessageLength) UNLIKELY + return context->setError(AL_INVALID_VALUE, "Debug message too long (%zu >= %d)", + newlen, MaxDebugMessageLength); length = static_cast<ALsizei>(newlen); } - else if(length > MaxDebugMessageLength) UNLIKELY + else if(length >= MaxDebugMessageLength) UNLIKELY return context->setError(AL_INVALID_VALUE, "Debug message too long (%d > %d)", length, MaxDebugMessageLength); diff --git a/alc/context.cpp b/alc/context.cpp index d4019bc9..bb4930ee 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -308,19 +308,22 @@ void ALCcontext::sendDebugMessage(DebugSource source, DebugType type, ALuint id, { static_assert(DebugSeverityBase+DebugSeverityCount <= 32, "Too many debug bits"); + /* MaxDebugMessageLength is the size including the null terminator, + * <length> does not include the null terminator. + */ if(length < 0) { size_t newlen{std::strlen(message)}; - if(newlen > MaxDebugMessageLength) UNLIKELY + if(newlen >= MaxDebugMessageLength) UNLIKELY { - ERR("Debug message too long (%zu > %d)\n", newlen, MaxDebugMessageLength); + ERR("Debug message too long (%zu >= %d)\n", newlen, MaxDebugMessageLength); return; } length = static_cast<ALsizei>(newlen); } - else if(length > MaxDebugMessageLength) UNLIKELY + else if(length >= MaxDebugMessageLength) UNLIKELY { - ERR("Debug message too long (%d > %d)\n", length, MaxDebugMessageLength); + ERR("Debug message too long (%d >= %d)\n", length, MaxDebugMessageLength); return; } |