https://bugs.llvm.org/show_bug.cgi?id=46598

            Bug ID: 46598
           Summary: GetArgsAndEnv() can not get correct 'envp' pointer on
                    linux
           Product: compiler-rt
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: compiler-rt
          Assignee: unassignedb...@nondot.org
          Reporter: zhaoma...@gmail.com
                CC: llvm-bugs@lists.llvm.org

GetArgsAndEnv() in sanitizer_linux.cpp:589 will count argc by detecting '\0':

============================================================================
static void GetArgsAndEnv(char ***argv, char ***envp) {
..........................................                                      
  if (&__libc_stack_end) {                                                      
    int argc = 0;                                                               
    while (stack_end[argc + 1]) argc++;  // <------------
..........................................
============================================================================
However googletest will shift the remainder of the argv list left by one
(llvm/utils/unittest/googletest/src/gtest.cc:ParseGoogleTestFlagsOnlyImpl())
and fork a new child process to run tests. 

============================================================================
template <typename CharType>
void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
..................................................
  if (remove_flag) {
    for (int j = i; j != *argc; j++) {
      argv[j] = argv[j + 1];
    }
    (*argc)--;
    i--;
  }
.................................................
}
============================================================================

If we exec unittest with one arg, then the stack end layout of new process will
like:

"argv[0]\0\0envp[0]....."

This will cause GetArgsAndEnv() get wrong argc and envp.

I think the second pass to read '/proc/self/environ' for GetArgsAndEnv() may be
a best choice.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to