With glibc 2.28 on an avx2 capable machine the wcsncmp function will produce the following error under valgrind: ==3667== Invalid read of size 32 ==3667== at 0x4F9CD61: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so) ==3667== by 0x400A33: main (wcs.c:22) ==3667== Address 0x5201110 is 208 bytes inside a block of size 216 alloc'd ==3667== at 0x4C30E4B: malloc (vg_replace_malloc.c:299) ==3667== by 0x4009CA: main (wcs.c:18) ==3667== ==3667== Invalid read of size 32 ==3667== at 0x4F9CD66: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so) ==3667== by 0x400A33: main (wcs.c:22) ==3667== Address 0x5201130 is 16 bytes after a block of size 224 in arena "client" ==3667== ==3667== Conditional jump or move depends on uninitialised value(s) ==3667== at 0x4F9CE21: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so) ==3667== by 0x400A33: main (wcs.c:22) ==3667== This probably comes from the following glibc commit glibc-2.27.9000-436-g1457016: commit 1457016337072d1b6739f571846b619596990cb7 Author: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> Date: Thu May 3 11:09:30 2018 -0500 x86-64: Optimize strcmp/wcscmp and strncmp/wcsncmp with AVX2 strcmp, wcscmp and strncmp have overrides in valgrind shared/vg_replace_strmem.c. But wcsncmp doesn't.
Created attachment 116617 [details] Add wcsncmp override and testcase. Proposed patch.
commit cf00e0e59def011e40e2c7993aab23970841dd03 Author: Mark Wielaard <mark@klomp.org> Date: Sat Dec 1 23:54:40 2018 +0100 Bug 401627 - Add wcsncmp override and testcase. glibc 2.28 added an avx2 optimized variant of wstrncmp which memcheck cannot proof correct. Add a simple override in vg_replace_strmem.c.