]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r6553/6 (Intercept __stpcpy_chk. (Dirk Mueller))
authorJulian Seward <jseward@acm.org>
Mon, 29 Jan 2007 01:07:21 +0000 (01:07 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 29 Jan 2007 01:07:21 +0000 (01:07 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6558

memcheck/mc_replace_strmem.c

index d385c7eb1e402b400d8e320bed2da7c720f21fb1..27e292d3bdc93f6d569a8c720e9dcd8dcaebf57e 100644 (file)
@@ -547,7 +547,8 @@ 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. */
+/* glibc variant of strcpy that checks the dest is big enough.
+   Copied from glibc-2.5/debug/test-stpcpy_chk.c. */
 #define GLIBC25___STRCPY_CHK(soname,fnname) \
    char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
                                (char* dst, const char* src, SizeT len); \
@@ -573,6 +574,32 @@ GLIBC232_RAWMEMCHR(m_libc_so_star, rawmemchr)
 GLIBC25___STRCPY_CHK(m_libc_so_star, __strcpy_chk)
 
 
+/* glibc variant of stpcpy that checks the dest is big enough.
+   Copied from glibc-2.5/debug/test-stpcpy_chk.c. */
+#define GLIBC25___STPCPY_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); \
+      if (! len) \
+         goto badness; \
+      while ((*dst++ = *src++) != '\0') \
+         if (--len == 0) \
+            goto badness; \
+      return dst - 1; \
+     badness: \
+      VALGRIND_PRINTF_BACKTRACE( \
+         "***buffer overflow detected ***: program terminated"); \
+     _exit(127); \
+     /*NOTREACHED*/ \
+     return NULL; \
+   }
+
+GLIBC25___STPCPY_CHK(m_libc_so_star, __stpcpy_chk)
+
+
 /* mempcpy */
 #define GLIBC25_MEMPCPY(soname, fnname) \
    void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \