From: Florian Krohm Date: Thu, 9 Oct 2014 19:22:44 +0000 (+0000) Subject: Merge revisions 14213 and 14612 from the BUF_REMOVAL branch to trunk. X-Git-Tag: svn/VALGRIND_3_11_0~932 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15ddd0c0d99e2dcf9cb4f1ae8dbb36043dbaab9f;p=thirdparty%2Fvalgrind.git Merge revisions 14213 and 14612 from the BUF_REMOVAL branch to trunk. The change removes the PATH_MAX limitation from the linux launcher. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14614 --- diff --git a/coregrind/launcher-linux.c b/coregrind/launcher-linux.c index c91c41c768..64e799c766 100644 --- a/coregrind/launcher-linux.c +++ b/coregrind/launcher-linux.c @@ -51,7 +51,6 @@ #include #include #include -#include // PATH_MAX #ifndef EM_X86_64 #define EM_X86_64 62 // elf.h doesn't define this on some older systems @@ -279,7 +278,7 @@ int main(int argc, char** argv, char** envp) const char *default_platform; const char *cp; char *toolfile; - char launcher_name[PATH_MAX+1]; + const char *launcher_name; char* new_line; char** new_env; @@ -358,17 +357,34 @@ int main(int argc, char** argv, char** envp) /* Figure out the name of this executable (viz, the launcher), so we can tell stage2. stage2 will use the name for recursive invocations of valgrind on child processes. */ - memset(launcher_name, 0, PATH_MAX+1); - r = readlink("/proc/self/exe", launcher_name, PATH_MAX); - if (r == -1) { - /* If /proc/self/exe can't be followed, don't give up. Instead - continue with an empty string for VALGRIND_LAUNCHER. In the - sys_execve wrapper, this is tested, and if found to be empty, - fail the execve. */ - fprintf(stderr, "valgrind: warning (non-fatal): " - "readlink(\"/proc/self/exe\") failed.\n"); - fprintf(stderr, "valgrind: continuing, however --trace-children=yes " - "will not work.\n"); + unsigned bufsiz = 0; + char *buf = NULL; + + while (42) { + bufsiz += 500; + buf = realloc(buf, bufsiz); + if (buf == NULL) + barf("realloc of buf failed."); + r = readlink("/proc/self/exe", buf, bufsiz); + if (r == -1) { + /* If /proc/self/exe can't be followed, don't give up. Instead + continue with an empty string for VALGRIND_LAUNCHER. In the + sys_execve wrapper, this is tested, and if found to be empty, + fail the execve. */ + fprintf(stderr, "valgrind: warning (non-fatal): " + "readlink(\"/proc/self/exe\") failed.\n"); + fprintf(stderr, "valgrind: continuing, however --trace-children=yes " + "will not work.\n"); + launcher_name = ""; + break; + } + if (r == bufsiz) continue; // buffer to small; retry + + assert(r < bufsiz); // paranoia + + buf[r] = '\0'; + launcher_name = buf; + break; } /* tediously augment the env: VALGRIND_LAUNCHER=launcher_name */