]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 454040 - Add intercept for memmem on s390x
authorAndreas Arnez <arnez@linux.ibm.com>
Thu, 19 May 2022 11:54:06 +0000 (13:54 +0200)
committerAndreas Arnez <arnez@linux.ibm.com>
Thu, 7 Jul 2022 12:23:06 +0000 (14:23 +0200)
Memcheck may report false positives in an optimized version of memmem on
s390x, specifically on arch13 systems.  Prevent this by adding an
intercept for memmem on s390x platforms.

NEWS
shared/vg_replace_strmem.c

diff --git a/NEWS b/NEWS
index 13b576e873350c709461c2445da72d57acc217bd..b3c3590b90044407f22fcc0b3fb36abe3c8f316d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 453055  shared_timed_mutex drd test fails with "Lock shared failed" message
 453602  Missing command line option to enable/disable debuginfod
 452802  Handle lld 9+ split RW PT_LOAD segments correctly
+454040  s390x: False-positive memcheck:cond in memmem on arch13 systems 
 456171  [PATCH] FreeBSD: Don't record address errors when accessing the 'kern.ps_strings' sysctl struct
 n-i-bz  Implement vgdb invoker on FreeBSD
 
index aab1413917d64f43689ec3d32ce0c8f22390517a..71b0e14cf5d49d30b6ef49b0fee99141126e9492 100644 (file)
    20430 WMEMCHR
    20440 WCSNLEN
    20450 WSTRNCMP
+   20460 MEMMEM
 */
 
 #if defined(VGO_solaris)
@@ -1800,6 +1801,41 @@ static inline void my_exit ( int x )
 
 #endif
 
+/*---------------------- memmem ----------------------*/
+
+#define MEMMEM(soname, fnname) \
+   void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \
+         (const void* haystack, SizeT hlen, const void* needle, SizeT nlen); \
+   void* VG_REPLACE_FUNCTION_EZU(20460,soname,fnname) \
+         (const void* haystack, SizeT hlen, const void* needle, SizeT nlen) \
+   { \
+      const HChar* h = haystack; \
+      const HChar* n = needle; \
+      \
+      /* If the needle is the empty string, match immediately. */ \
+      if (nlen == 0) return CONST_CAST(void *,h); \
+      \
+      HChar n0 = n[0]; \
+      \
+      for (; hlen >= nlen; hlen--, h++) { \
+         if (h[0] != n0) continue; \
+         \
+         UWord i; \
+         for (i = 1; i < nlen; i++) { \
+            if (n[i] != h[i]) \
+               break; \
+         } \
+         if (i == nlen) \
+           return CONST_CAST(HChar *,h); \
+         \
+      } \
+      return NULL; \
+   }
+
+#if defined(VGP_s390x_linux)
+ MEMMEM(VG_Z_LIBC_SONAME,          memmem)
+#endif
+
 
 /*---------------------- strpbrk ----------------------*/