diff mbox series

Don't allow the pool allocator to be configured to allocate zero-sized objects

Message ID 6e5f2b4e-a21b-274a-6bbf-5980ef4d46a8@arm.com
State New
Headers show
Series Don't allow the pool allocator to be configured to allocate zero-sized objects | expand

Commit Message

Richard Earnshaw (lists) Oct. 30, 2018, 10:55 a.m. UTC
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.

OK?

Comments

Richard Biener Oct. 30, 2018, 11:21 a.m. UTC | #1
On Tue, Oct 30, 2018 at 11:55 AM Richard Earnshaw (lists)
<Richard.Earnshaw@arm.com> wrote:
>

> 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.

>

> OK?


OK.
diff mbox series

Patch

diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
index c0a12920558..d2ee0005761 100644
--- a/gcc/alloc-pool.h
+++ b/gcc/alloc-pool.h
@@ -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*))