[llvm-bugs] [Bug 46598] New: GetArgsAndEnv() can not get correct 'envp' pointer on linux
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 6 04:44:37 PDT 2020
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: unassignedbugs at nondot.org
Reporter: zhaomaosu at gmail.com
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200706/42179da6/attachment-0001.html>
More information about the llvm-bugs
mailing list