glibc/malloc
Dennis Wölfing 2e0bbbfbf9 Add reallocarray function
The reallocarray function is an extension from OpenBSD.  It is an
integer-overflow-safe replacement for realloc(p, X*Y) and
malloc(X*Y) (realloc(NULL, X*Y)).  It can therefore help in preventing
certain security issues in code.

This is an updated version of a patch originally submitted by Rüdiger
Sonderfeld in May 2014 [1].

Checked on i686-linux-gnu and x86_64-linux-gnu.

[1] <https://sourceware.org/ml/libc-alpha/2014-05/msg00481.html>.

2017-05-30  Dennis Wölfing  <denniswoelfing@gmx.de>
            Rüdiger Sonderfeld  <ruediger@c-plusplus.de>

	* include/stdlib.h (__libc_reallocarray): New declaration.
	* malloc/Makefile (routines): Add reallocarray.
	(tests): Add tst-reallocarray.c.
	* malloc/Versions: Add reallocarray and __libc_reallocarray.
	* malloc/malloc-internal.h (check_mul_overflow_size_t): New inline
	function.
	* malloc/malloc.h (reallocarray): New declaration.
	* stdlib/stdlib.h (reallocarray): Likewise.
	* malloc/reallocarray.c: New file.
	* malloc/tst-reallocarray.c: New test file.
	* manual/memory.texi: Document reallocarray.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add reallocarray.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tilepro/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
2017-05-30 18:27:57 -03:00
..
arena.c Fix getting tunable values on big-endian (BZ #21109) 2017-02-08 14:17:17 +05:30
Depend
hooks.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
Makefile Add reallocarray function 2017-05-30 18:27:57 -03:00
malloc-hooks.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
malloc-internal.h Add reallocarray function 2017-05-30 18:27:57 -03:00
malloc.c Tweak realloc/MREMAP comment to be more accurate. 2017-05-03 16:28:01 -04:00
malloc.h Add reallocarray function 2017-05-30 18:27:57 -03:00
mallocbug.c Reformat malloc to gnu style. 2014-01-02 09:40:10 +01:00
mcheck-init.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mcheck.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mcheck.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
memusage.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
memusage.sh Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
memusagestat.c Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
morecore.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
mtrace.c Assume that O_CLOEXEC is always defined and works 2017-04-18 14:56:51 +02:00
mtrace.pl Update copyright dates not handled by scripts/update-copyrights. 2017-01-01 00:26:24 +00:00
obstack.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
obstack.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
reallocarray.c Add reallocarray function 2017-05-30 18:27:57 -03:00
scratch_buffer_grow_preserve.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
scratch_buffer_grow.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
scratch_buffer_set_array_size.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
set-freeres.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
thread-freeres.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-calloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-aux-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-aux-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-aux.c Fix failing test malloc/tst-interpose-nothread with GCC 7. 2017-03-21 16:41:56 +01:00
tst-interpose-aux.h Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-skeleton.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-static-nothread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-static-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-interpose-thread.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-backtrace.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-fork-deadlock.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-thread-exit.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc-thread-fail.c Increase some test timeouts. 2017-01-05 17:39:38 +00:00
tst-malloc-usable-static-tunables.c Initialize tunable list with the GLIBC_TUNABLES environment variable 2016-12-31 23:49:24 +05:30
tst-malloc-usable-static.c Add framework for tunables 2016-12-31 23:49:24 +05:30
tst-malloc-usable-tunables.c Initialize tunable list with the GLIBC_TUNABLES environment variable 2016-12-31 23:49:24 +05:30
tst-malloc-usable.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-malloc.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-mallocfork2.c Increase some test timeouts. 2017-01-05 17:39:38 +00:00
tst-mallocfork.c * malloc/tst-mallocfork.c (do_test): Make sure sa_flags is 2005-12-06 00:50:15 +00:00
tst-mallocstate.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mallopt.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mcheck.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-memalign.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mtrace.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-mtrace.sh Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-obstack.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-posix_memalign.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-pvalloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-realloc.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-reallocarray.c Add reallocarray function 2017-05-30 18:27:57 -03:00
tst-scratch_buffer.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
tst-trim1.c * malloc/tst-trim1.c: New file. 2007-12-16 22:57:57 +00:00
tst-valloc.c Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
Versions Add reallocarray function 2017-05-30 18:27:57 -03:00