From: Julian Seward Date: Mon, 29 Jan 2007 01:07:21 +0000 (+0000) Subject: Merge r6553/6 (Intercept __stpcpy_chk. (Dirk Mueller)) X-Git-Tag: svn/VALGRIND_3_2_3~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdb4a3976c5fee72046d4ad7b3caf7d812a8eb0a;p=thirdparty%2Fvalgrind.git Merge r6553/6 (Intercept __stpcpy_chk. (Dirk Mueller)) git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6558 --- diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c index d385c7eb1e..27e292d3bd 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mc_replace_strmem.c @@ -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) \