sysmalloc: Initialize previous size field of mmaped chunks

Message ID 20161028130449.BB0E9439942E0@oldenburg.str.redhat.com
State Committed
Headers

Commit Message

Florian Weimer Oct. 28, 2016, 1:04 p.m. UTC
  With different encodings of the header, the previous zero initialization
may be insufficient and produce an invalid encoding.

2016-10-27  Florian Weimer  <fweimer@redhat.com>

	* malloc/malloc.c (sysmalloc): Initialize previous size field of
	mmaped chunks.
  

Comments

Carlos O'Donell Oct. 28, 2016, 2:13 p.m. UTC | #1
On 10/28/2016 09:04 AM, Florian Weimer wrote:
> With different encodings of the header, the previous zero initialization
> may be insufficient and produce an invalid encoding.
> 
> 2016-10-27  Florian Weimer  <fweimer@redhat.com>
> 
> 	* malloc/malloc.c (sysmalloc): Initialize previous size field of
> 	mmaped chunks.
> 
> diff --git a/malloc/malloc.c b/malloc/malloc.c
> index 186e174..72d22bd 100644
> --- a/malloc/malloc.c
> +++ b/malloc/malloc.c
> @@ -2306,6 +2306,7 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
>                else
>                  {
>                    p = (mchunkptr) mm;
> +		  set_prev_size (p, 0);
>                    set_head (p, size | IS_MMAPPED);
>                  }
>  
 
Agreed. This looks good to me, and paves the way for the header
encodings to be non-zero.
  

Patch

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 186e174..72d22bd 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2306,6 +2306,7 @@  sysmalloc (INTERNAL_SIZE_T nb, mstate av)
               else
                 {
                   p = (mchunkptr) mm;
+		  set_prev_size (p, 0);
                   set_head (p, size | IS_MMAPPED);
                 }