Fix 393099 - posix_memalign() invalid write if alignment == 0

Bug and analysis by Gabriel Ganne
This commit is contained in:
Philippe Waroquiers 2018-04-15 08:06:43 +02:00
parent 718b47e184
commit d9204e9eed
2 changed files with 3 additions and 2 deletions

View File

@ -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; \
\

View File

@ -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);