]> granicus.if.org Git - gc/commitdiff
Fix hbp overflow in GC_install_counts
authorIvan Maidanski <ivmai@mail.ru>
Sun, 4 Nov 2018 08:59:11 +0000 (11:59 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 23 Nov 2018 22:16:45 +0000 (01:16 +0300)
(a cherry-pick of commits 6a32bb436a6d79 from 'master')

Issue #245 (bdwgc).

The overflow resulted in an infinite loop in GC_install_counts on Win32.

* headers.c (GC_install_counts): If hbp+=BOTTOM_SZ overflow is expected
then break the first loop; add comment.

headers.c

index d2c283c56752d908637ad9d7193b3746d1f7339e..462da89f545f900cc73f73e5885e774d5765febf 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -284,6 +284,8 @@ GC_INNER GC_bool GC_install_counts(struct hblk *h, size_t sz/* bytes */)
 
     for (hbp = h; (word)hbp < (word)h + sz; hbp += BOTTOM_SZ) {
         if (!get_index((word) hbp)) return(FALSE);
+        if ((word)hbp > (~(word)0) - (word)BOTTOM_SZ * HBLKSIZE)
+            break; /* overflow of hbp+=BOTTOM_SZ is expected */
     }
     if (!get_index((word)h + sz - 1)) return(FALSE);
     for (hbp = h + 1; (word)hbp < (word)h + sz; hbp += 1) {