]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r6462 (Intercept/replace glibc-2.5's __strcpy_chk function)
authorJulian Seward <jseward@acm.org>
Sun, 31 Dec 2006 02:26:57 +0000 (02:26 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 31 Dec 2006 02:26:57 +0000 (02:26 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6464

memcheck/mc_replace_strmem.c

index 27fe0464d0b6b95a4387d6872b3d2a67fdeccafc..fe0a7868190cf117b0a51c782411c896beaf1cf1 100644 (file)
@@ -536,6 +536,32 @@ GLIBC232_STRCHRNUL(m_libc_so_star, strchrnul)
 GLIBC232_RAWMEMCHR(m_libc_so_star, 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_so_star, __strcpy_chk)
+
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/