From: Julian Seward Date: Sun, 31 Dec 2006 00:22:30 +0000 (+0000) Subject: Intercept/replace glibc-2.5's __strcpy_chk function for the usual X-Git-Tag: svn/VALGRIND_3_3_0~450 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daf075a233b485d5ec890b5b8a438570c337559c;p=thirdparty%2Fvalgrind.git Intercept/replace glibc-2.5's __strcpy_chk function for the usual 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 --- diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c index a0eed00446..f4aefcd0ab 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mc_replace_strmem.c @@ -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 ---*/ /*------------------------------------------------------------*/