]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't allow the pool allocator to be configured to allocate zero-sized objects
authorrearnsha <rearnsha@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Oct 2018 11:33:24 +0000 (11:33 +0000)
committerrearnsha <rearnsha@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Oct 2018 11:33:24 +0000 (11:33 +0000)
PR bootstrap/87747 would have been significantly easier to track down if
the pool allocator had faulted an attempt to configure it to allocate
zero-sized objects.  Instead, this slipped through and we later hit
memory corruption when the assumed size turned out to be different to
the configured size.

While, theoretically, there might be a use case for this, it seems
unlikely to me that GCC would have such a use.  So this patch adds a
checking assert that the object size is not zero.

* alloc-pool.h (base_pool_allocator <TBlockAllocator>::initialize):
Assert that the allocation size is not zero.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265620 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/alloc-pool.h

index da7b998f39af34ef898e50f1560c2f45bbb73b1a..c07d3ad96680558156a2492cff82ce38ae725979 100644 (file)
@@ -1,3 +1,8 @@
+2018-10-30  Richard Earnshaw  <rearnsha@arm.com>
+
+       * alloc-pool.h (base_pool_allocator <TBlockAllocator>::initialize):
+       Assert that the allocation size is not zero.
+
 2018-10-30  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/87800
index c0a129205582cd39a06c450fc477f2b290e67416..d2ee00057611453cee567bab76d0e1f19effb238 100644 (file)
@@ -256,6 +256,7 @@ base_pool_allocator <TBlockAllocator>::initialize ()
   size_t size = m_size;
 
   gcc_checking_assert (m_name);
+  gcc_checking_assert (m_size);
 
   /* Make size large enough to store the list header.  */
   if (size < sizeof (allocation_pool_list*))