Prechádzať zdrojové kódy

Fix possible overrun

- closes https://github.com/assimp/assimp/issues/3425
Kim Kulling 4 rokov pred
rodič
commit
a45878c41a
1 zmenil súbory, kde vykonal 5 pridanie a 2 odobranie
  1. 5 2
      code/Common/RemoveComments.cpp

+ 5 - 2
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;