From a45878c41ad735a1e5f1755fcf0be14788f42021 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 27 Aug 2021 14:04:00 +0200 Subject: [PATCH] Fix possible overrun - closes https://github.com/assimp/assimp/issues/3425 --- code/Common/RemoveComments.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/Common/RemoveComments.cpp b/code/Common/RemoveComments.cpp index d1c2ac391..e1ba99761 100644 --- a/code/Common/RemoveComments.cpp +++ b/code/Common/RemoveComments.cpp @@ -59,13 +59,16 @@ void CommentRemover::RemoveLineComments(const char* szComment, ai_assert(nullptr != szBuffer); ai_assert(*szComment); - const size_t len = strlen(szComment); + size_t len = strlen(szComment); + const size_t lenBuffer = strlen(szBuffer); + if (len > lenBuffer) { + len = lenBuffer; + } while (*szBuffer) { // skip over quotes if (*szBuffer == '\"' || *szBuffer == '\'') while (*szBuffer++ && *szBuffer != '\"' && *szBuffer != '\''); - if (!strncmp(szBuffer,szComment,len)) { while (!IsLineEnd(*szBuffer)) *szBuffer++ = chReplacement;