https://bugs.kde.org/show_bug.cgi?id=393099
Bug ID: 393099 Summary: posix_memalign() invalid write if alignment == 0 Product: valgrind Version: 3.13.0 Platform: Debian stable OS: Linux Status: UNCONFIRMED Severity: normal Priority: NOR Component: memcheck Assignee: jsew...@acm.org Reporter: gabriel.ga...@gmail.com Target Milestone: --- Created attachment 111999 --> https://bugs.kde.org/attachment.cgi?id=111999&action=edit posix_memalign() test Hi, The attached file tests posix_memalign() with an invalid alignment of 0. The expected behavior is for posix_memalign() to return EINVAL and to leave memptr untouched, or to set it to NULL. I propose the following patch I made on valgrind-3.13.0 sources : * add a test on alignment == 0 * set mem to NULL explicitely so as to be validly test its value after calling posix_memalign() on failure --- ./coregrind/m_replacemalloc/vg_replace_malloc.c.orig +++ ./coregrind/m_replacemalloc/vg_replace_malloc.c @@ -997,11 +997,11 @@ int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \ ( void **memptr, SizeT alignment, SizeT size ) \ { \ - void *mem; \ + void *mem = NULL; \ \ /* 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; \ \ -- You are receiving this mail because: You are watching all bug changes.