]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix heap-buffer-overflow in checkModFileAlias [PR 99337]
authorIain Buclaw <ibuclaw@gdcproject.org>
Wed, 3 Mar 2021 14:34:04 +0000 (15:34 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Wed, 3 Mar 2021 18:30:23 +0000 (19:30 +0100)
The code wrongly assumed memcmp did not read past the mismatch.

gcc/d/ChangeLog:

PR d/99337
* dmd/dmodule.c (checkModFileAlias): Don't read past buffer in
  comparison.

(cherry picked from commit d6177870dd2696501e3b8d3930fd5549d4acaeae)

gcc/d/dmd/dmodule.c

index bf1c0c1f0d901aa1d0ec4835f342a2e5f5b061db..c67626c00e59bb756029af28f94debcc426f31e1 100644 (file)
@@ -202,7 +202,7 @@ static void checkModFileAlias(OutBuffer *buf, OutBuffer *dotmods,
         const char *m = (*ms)[j];
         const char *q = strchr(m, '=');
         assert(q);
-        if (dotmods->offset <= (size_t)(q - m) && memcmp(dotmods->peekString(), m, q - m) == 0)
+        if (dotmods->offset == (size_t)(q - m) && memcmp(dotmods->peekString(), m, q - m) == 0)
         {
             buf->reset();
             size_t qlen = strlen(q + 1);