Blame SOURCES/glibc-rh1662842.patch

147e83
commit b50dd3bc8cbb1efe85399b03d7e6c0310c2ead84
147e83
Author: Florian Weimer <fw@deneb.enyo.de>
147e83
Date:   Mon Dec 31 22:04:36 2018 +0100
147e83
147e83
    malloc: Always call memcpy in _int_realloc [BZ #24027]
147e83
    
147e83
    This commit removes the custom memcpy implementation from _int_realloc
147e83
    for small chunk sizes.  The ncopies variable has the wrong type, and
147e83
    an integer wraparound could cause the existing code to copy too few
147e83
    elements (leaving the new memory region mostly uninitialized).
147e83
    Therefore, removing this code fixes bug 24027.
147e83
147e83
diff -rup a/malloc/malloc.c b/malloc/malloc.c
147e83
--- a/malloc/malloc.c	2019-03-26 14:12:59.364333388 -0400
147e83
+++ b/malloc/malloc.c	2019-03-26 14:17:17.373475418 -0400
147e83
@@ -4214,11 +4214,6 @@ _int_realloc(mstate av, mchunkptr oldp,
147e83
   mchunkptr        bck;             /* misc temp for linking */
147e83
   mchunkptr        fwd;             /* misc temp for linking */
147e83
 
147e83
-  unsigned long    copysize;        /* bytes to copy */
147e83
-  unsigned int     ncopies;         /* INTERNAL_SIZE_T words to copy */
147e83
-  INTERNAL_SIZE_T* s;               /* copy source */
147e83
-  INTERNAL_SIZE_T* d;               /* copy destination */
147e83
-
147e83
   const char *errstr = NULL;
147e83
 
147e83
   /* oldmem size */
147e83
@@ -4291,39 +4286,7 @@ _int_realloc(mstate av, mchunkptr oldp,
147e83
 	newp = oldp;
147e83
       }
147e83
       else {
147e83
-	/*
147e83
-	  Unroll copy of <= 36 bytes (72 if 8byte sizes)
147e83
-	  We know that contents have an odd number of
147e83
-	  INTERNAL_SIZE_T-sized words; minimally 3.
147e83
-	*/
147e83
-
147e83
-	copysize = oldsize - SIZE_SZ;
147e83
-	s = (INTERNAL_SIZE_T*)(chunk2mem(oldp));
147e83
-	d = (INTERNAL_SIZE_T*)(newmem);
147e83
-	ncopies = copysize / sizeof(INTERNAL_SIZE_T);
147e83
-	assert(ncopies >= 3);
147e83
-
147e83
-	if (ncopies > 9)
147e83
-	  MALLOC_COPY(d, s, copysize);
147e83
-
147e83
-	else {
147e83
-	  *(d+0) = *(s+0);
147e83
-	  *(d+1) = *(s+1);
147e83
-	  *(d+2) = *(s+2);
147e83
-	  if (ncopies > 4) {
147e83
-	    *(d+3) = *(s+3);
147e83
-	    *(d+4) = *(s+4);
147e83
-	    if (ncopies > 6) {
147e83
-	      *(d+5) = *(s+5);
147e83
-	      *(d+6) = *(s+6);
147e83
-	      if (ncopies > 8) {
147e83
-		*(d+7) = *(s+7);
147e83
-		*(d+8) = *(s+8);
147e83
-	      }
147e83
-	    }
147e83
-	  }
147e83
-	}
147e83
-
147e83
+	memcpy (newmem, chunk2mem (oldp), oldsize - SIZE_SZ);
147e83
 	_int_free(av, oldp, 1);
147e83
 	check_inuse_chunk(av, newp);
147e83
 	return chunk2mem(newp);