]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
It appears glibc-2.5's getenv() function steps along environment
authorJulian Seward <jseward@acm.org>
Sun, 11 Mar 2007 13:00:34 +0000 (13:00 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 11 Mar 2007 13:00:34 +0000 (13:00 +0000)
strings in 16-bit chunks, which can cause false errors in some cases
(sigh).  So do the usual thing and replace it.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6640

memcheck/mc_replace_strmem.c

index b7d016f00e982360b3a5997db46de62daec12902..02b90a767350392d633127c7a38b9f4a3d5db36a 100644 (file)
@@ -670,6 +670,40 @@ GLIBC25_MEMPCPY(m_libc_soname, mempcpy)
 GLIBC25_MEMPCPY(m_ld_so_1,     mempcpy) /* ld.so.1 */
 
 
+/* getenv.  glibc-2.5 steps along the env strings in 2 byte chunks
+   which means it sometimes overreads.  sigh. */
+#define GLIBC25_GETENV(soname, fnname) \
+   char* VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* name0 ); \
+   char* VG_REPLACE_FUNCTION_ZU(soname,fnname)( const char* name0 )  \
+   { \
+      char** ep; \
+      char* cand; \
+      char* name; \
+      extern char** __environ; \
+      if (__environ == NULL || name0 == NULL || name0[0] == '\0') \
+         return NULL; \
+      for (ep = __environ; *ep; ep++) { \
+         cand = *ep; \
+         name = (char*)name0; \
+         /* advance cand and name until either points at zero or \
+            until what they both point at differs. */ \
+         while (1) { \
+            if (*cand == 0 || *name == 0) \
+               break; \
+            if (*cand != *name) \
+               break; \
+            cand++; \
+            name++; \
+         } \
+         if (*name == 0 && *cand == '=') \
+            return cand+1; \
+     } \
+     return NULL; \
+   }
+
+GLIBC25_GETENV(m_libc_soname, getenv)
+
+
 /*------------------------------------------------------------*/
 /*--- AIX stuff only after this point                      ---*/
 /*------------------------------------------------------------*/