From: Ilya Enkovich Date: Thu, 9 Apr 2015 10:11:30 +0000 (+0000) Subject: mpx_wrappers.c (__mpx_wrapper_memmove): Add zero length check. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3ba99d8a035e95aa93eb2fc56739f63c36582213;p=gcc.git mpx_wrappers.c (__mpx_wrapper_memmove): Add zero length check. libmpx/ * mpxwrap/mpx_wrappers.c (__mpx_wrapper_memmove): Add zero length check. gcc/testsuite/ * gcc.target/i386/mpx/memmove-zero-length.c: New. From-SVN: r221944 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1cd869a0fb5..90e467abb41 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-04-09 Ilya Enkovich + + * gcc.target/i386/mpx/memmove-zero-length.c: New. + 2015-04-09 Kirill Yukhin PR target/65676 diff --git a/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c b/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c new file mode 100644 index 00000000000..78bfdebff03 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/mpx/memmove-zero-length.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + + +#include "mpx-check.h" +#include "string.h" + +int mpx_test (int argc, const char **argv) +{ + int *buf = (int *)malloc (100 * sizeof(int)); + + memmove (buf, NULL, 0); + memmove (NULL, buf, 0); + + free (buf); + + return 0; +} diff --git a/libmpx/ChangeLog b/libmpx/ChangeLog index 6b05278b0d0..56c3c5f1b2b 100644 --- a/libmpx/ChangeLog +++ b/libmpx/ChangeLog @@ -1,3 +1,8 @@ +2015-04-09 Ilya Enkovich + + * mpxwrap/mpx_wrappers.c (__mpx_wrapper_memmove): Add + zero length check. + 2015-04-02 Ilya Enkovich PR driver/65444 diff --git a/libmpx/mpxwrap/mpx_wrappers.c b/libmpx/mpxwrap/mpx_wrappers.c index ef4be8d0a39..58670aae481 100644 --- a/libmpx/mpxwrap/mpx_wrappers.c +++ b/libmpx/mpxwrap/mpx_wrappers.c @@ -97,6 +97,9 @@ __mpx_wrapper_memmove (void *dst, const void *src, size_t n) size_t offset_src = ((size_t) s) & (sizeof (void *) - 1); size_t offset_dst = ((size_t) d) & (sizeof (void *) - 1); + if (n == 0) + return ret; + __bnd_chk_ptr_bounds (dst, n); __bnd_chk_ptr_bounds (src, n);