With glibc 2.24, valgrind emits three "invalid read of size 1" for the program below. This is because the strtok implementation on s390x invokes __strcspn_c(), which operates 4-byte-wise on a word-aligned string pointer. The "invalid reads" refer to the three bytes between the 5-byte buffer and the next word boundary. On some other platforms the strtok implementation calls strcspn via a PLT slot, in which case Valgrind's replacement for strcspn gets invoked instead. -- >8 -- #include <string.h> int main(int argc, char *argv[]) { strtok(strdup("xxxx"), "ab"); return 0; }
Seems like a simple wrapper for "__strcspn_c" would suffice in shared/vg_replace_strmem.c. Would you please try the following patch (also attached) against Valgrind from SVN [1] --- shared/vg_replace_strmem.c (revision 16420) +++ shared/vg_replace_strmem.c (working copy) @@ -1721,6 +1721,7 @@ #if defined(VGO_linux) STRCSPN(VG_Z_LIBC_SONAME, strcspn) + STRCSPN(VG_Z_LIBC_SONAME, __strcspn_c) #elif defined(VGO_darwin) [1] http://valgrind.org/downloads/repository.html
Created attachment 105808 [details] simple patch
(In reply to Ivo Raisr from comment #1) > Seems like a simple wrapper for "__strcspn_c" would suffice in > shared/vg_replace_strmem.c. > > Would you please try the following patch (also attached) against Valgrind > from SVN [1] > [...] Confirmed, this works. Thanks! Instead of the s390x-specific function name "__strcspn_c", maybe we should better redirect to the common alias "__GI_strcspn". The following patch works as well: Index: vg_replace_strmem.c =================================================================== --- vg_replace_strmem.c (revision 16429) +++ vg_replace_strmem.c (working copy) @@ -1721,6 +1721,7 @@ #if defined(VGO_linux) STRCSPN(VG_Z_LIBC_SONAME, strcspn) + STRCSPN(VG_Z_LIBC_SONAME, __GI_strcspn) #elif defined(VGO_darwin)
I will integrate the change with __GI_strcspn() after Valgrind 3.13 is released.
Fixed in Valgrind SVN r16436.