|
From: Philippe W. <phi...@so...> - 2018-04-15 06:08:02
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=d9204e9eedc8a671e6f035318d28cb55440c3a8b commit d9204e9eedc8a671e6f035318d28cb55440c3a8b Author: Philippe Waroquiers <phi...@sk...> Date: Sun Apr 15 08:06:43 2018 +0200 Fix 393099 - posix_memalign() invalid write if alignment == 0 Bug and analysis by Gabriel Ganne Diff: --- coregrind/m_replacemalloc/vg_replace_malloc.c | 3 ++- memcheck/tests/memalign2.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 9fb0069..11f6a90 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1001,7 +1001,8 @@ static void init(void); \ /* Test whether the alignment argument is valid. It must be \ a power of two multiple of sizeof (void *). */ \ - if (alignment % sizeof (void *) != 0 \ + if (alignment == 0 \ + || alignment % sizeof (void *) != 0 \ || (alignment & (alignment - 1)) != 0) \ return VKI_EINVAL; \ \ diff --git a/memcheck/tests/memalign2.c b/memcheck/tests/memalign2.c index 39069a6..95d1335 100644 --- a/memcheck/tests/memalign2.c +++ b/memcheck/tests/memalign2.c @@ -82,7 +82,7 @@ int main ( void ) # define PM(a,b,c) posix_memalign((void**)a, b, c) res = PM(&p, -1,100); assert(EINVAL == res); - res = PM(&p, 0, 100); assert(0 == res && 0 == (long)p % 8); + res = PM(&p, 0, 100); assert(EINVAL == res); res = PM(&p, 1, 100); assert(EINVAL == res); res = PM(&p, 2, 100); assert(EINVAL == res); res = PM(&p, 3, 100); assert(EINVAL == res); |