From: Dirk Mueller Date: Thu, 19 Apr 2007 09:47:32 +0000 (+0000) Subject: wrap env related functions to be able to track undefined X-Git-Tag: svn/VALGRIND_3_3_0~285 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40de8b88ed2795cfebfcc5245d6c5376222295b9;p=thirdparty%2Fvalgrind.git wrap env related functions to be able to track undefined values better git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6706 --- diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c index b7d016f00e..3db518845b 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mc_replace_strmem.c @@ -670,6 +670,67 @@ GLIBC25_MEMPCPY(m_libc_soname, mempcpy) GLIBC25_MEMPCPY(m_ld_so_1, mempcpy) /* ld.so.1 */ +/*------------------------------------------------------------*/ +/*--- Improve definedness checking of process environment ---*/ +/*------------------------------------------------------------*/ + +/* putenv */ +int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string); +int VG_WRAP_FUNCTION_ZU(m_libc_soname, putenv) (char* string) +{ + OrigFn fn; + Word result; + const char* p = string; + VALGRIND_GET_ORIG_FN(fn); + /* Now by walking over the string we magically produce + traces when hitting undefined memory. */ + if (p) + while (*p++) + ; + CALL_FN_W_W(result, fn, string); + return result; +} + +/* unsetenv */ +int VG_WRAP_FUNCTION_ZU(m_libc_soname, unsetenv) (const char* name); +int VG_WRAP_FUNCTION_ZU(m_libc_soname, unsetenv) (const char* name) +{ + OrigFn fn; + Word result; + const char* p = name; + VALGRIND_GET_ORIG_FN(fn); + /* Now by walking over the string we magically produce + traces when hitting undefined memory. */ + if (p) + while (*p++) + ; + CALL_FN_W_W(result, fn, name); + return result; +} + +/* setenv */ +int VG_WRAP_FUNCTION_ZU(m_libc_soname, setenv) + (const char* name, const char* value, int overwrite); +int VG_WRAP_FUNCTION_ZU(m_libc_soname, setenv) + (const char* name, const char* value, int overwrite) +{ + OrigFn fn; + Word result; + const char* p; + VALGRIND_GET_ORIG_FN(fn); + /* Now by walking over the string we magically produce + traces when hitting undefined memory. */ + if (name) + for (p = name; *p; p++) + ; + if (value) + for (p = value; *p; p++) + ; + VALGRIND_CHECK_VALUE_IS_DEFINED (overwrite); + CALL_FN_W_WWW(result, fn, name, value, overwrite); + return result; +} + /*------------------------------------------------------------*/ /*--- AIX stuff only after this point ---*/ /*------------------------------------------------------------*/