Example program: #include <stdio.h> #include <stdlib.h> int main(void) { printf("%s\n", getenv("FOO/BAR")); return 0; } I can successfully run it with: env 'FOO/BAR=1' ./test However, with valgrind FOO/BAR is NULL and it crashes: env 'FOO/BAR=1' valgrind ./test ==77478== Invalid read of size 1 ==77478== at 0x4C2FD72: strlen (vg_replace_strmem.c:458) ==77478== by 0x4EA7D01: puts (ioputs.c:35) ==77478== by 0x1086A1: main (in /home/tss/test)
I just tried to reproduce this (admittedly on FreeBSD) and could see no problem. Which shell is this? Not that that should matter. Can you build Valgrind from source? If so, could you change the variable 'debug' to be 'True' at the start of setup_client_env, and rerun the test.
Looks like there's something weird in the Debian packaging. If I get the sources with "apt source valgrind" and then compile it with: ./configure --prefix=/tmp/valgrind && make && sudo make install Then it works correctly. If I compile the sources with "dpkg-buildpacakge -b" then it's again wrongly NULL. I guess I'll report it to Debian bugs then.
An optimization (LTO?) problem perhaps. Ill leave this open - can you please update if the Debian folks have more info?
I can also not replicate this with the Fedora packaged valgrind.
There are two possible places that this could be going wrong. 1. The valgrind launcher. This modifies the environment to insert a couple of variables so that Valgrind will be able to load a couple of shared libraries. 2. The tool code that sets up the client env. This synthesizes a new env for the client, adding a LD_PRELOAD. To eliminate number 1 could you try something like this: export VALGRIND_LAUNCHER=`which valgrind` export VALGRIND_LIB=/usr/libexec/valgrind env 'FOO/BAR=1' /usr/libexec/valgrind/memcheck-amd64-linux ./395266 (note that this is NOT a recommended way to run Valgrind!)
(In reply to Paul Floyd from comment #5) > To eliminate number 1 could you try something like this: > > export VALGRIND_LAUNCHER=`which valgrind` > export VALGRIND_LIB=/usr/libexec/valgrind > env 'FOO/BAR=1' /usr/libexec/valgrind/memcheck-amd64-linux ./395266 Testing in Ubuntu 20.04 in Macbook it runs correctly (no crash): export VALGRIND_LAUNCHER=`which valgrind` export VALGRIND_LIB=/usr/lib/aarch64-linux-gnu/valgrind env 'FOO/BAR=1' /usr/lib/aarch64-linux-gnu/valgrind/memcheck-arm64-linux ./test
Do you have the original problem with Ubuntu as well?
Yes, original problem exists in Ubuntu 20.04.
I now see what is happening. On kubuntu, the valgrind package uses a shell wrapper. This sets a couple of environment variables (LD_LIBRARY_PATH to pick up debug libs and GLIBCXX_FORCE_NEW=1 to prevent new from using a cache). Then it execs valgrind.bin. Since FOO/BAR is not a valid environment variable (at least , not as far as bash is concerned, env does allow it) then it doesn't get propagated to valgrind.bin and the guest exe crashes. If you run env 'FOO/BAR=1' valgrind.bin ./test then it should work normally.