]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Intercept/replace glibc-2.5's __strcpy_chk function for the usual
authorJulian Seward <jseward@acm.org>
Sun, 31 Dec 2006 00:22:30 +0000 (00:22 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 31 Dec 2006 00:22:30 +0000 (00:22 +0000)
reasons: it reads word-sized chunks from memory and so produces lots
of errors in SuSE 10.2 (amd64).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6462

memcheck/mc_replace_strmem.c

index a0eed004463f4ea1d8a90dbfde820fa108fbefb9..f4aefcd0ab419394b5055a04c77b3257dc8a3d14 100644 (file)
@@ -532,6 +532,32 @@ GLIBC232_STRCHRNUL(m_libc_soname, strchrnul)
 GLIBC232_RAWMEMCHR(m_libc_soname, rawmemchr)
 
 
+/* glibc variant of strcpy that checks the dest is big enough. */
+#define GLIBC25___STRCPY_CHK(soname,fnname) \
+   char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
+                               (char* dst, const char* src, SizeT len); \
+   char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
+                               (char* dst, const char* src, SizeT len) \
+   { \
+      extern void _exit(int status); \
+      char* ret = dst; \
+      if (! len) \
+         goto badness; \
+      while ((*dst++ = *src++) != '\0') \
+         if (--len == 0) \
+            goto badness; \
+      return ret; \
+     badness: \
+      VALGRIND_PRINTF_BACKTRACE( \
+         "***buffer overflow detected ***: program terminated"); \
+     _exit(127); \
+     /*NOTREACHED*/ \
+     return NULL; \
+   }
+
+GLIBC25___STRCPY_CHK(m_libc_soname, __strcpy_chk)
+
+
 /*------------------------------------------------------------*/
 /*--- AIX stuff only after this point                      ---*/
 /*------------------------------------------------------------*/