https://bugs.kde.org/show_bug.cgi?id=422261
Bug ID: 422261 Summary: platform selection fails for unqualified pathname Product: valgrind Version: unspecified Platform: Compiled Sources OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: general Assignee: jsew...@acm.org Reporter: michael.woj...@microfocus.com Target Milestone: --- SUMMARY coregrind/launcher-linux.c calls select_platform() to determine the client platform. select_platform uses the wrong variable in attempting to open the client binary, resulting in no platform detection and fallback to the default platform (e.g. x86-64) if the client is specified as an unqualified filename (i.e. neither an absolute nor relative pathname). The problem and fix are trivial: if (strchr(clientname, '/') == NULL) client = find_client(clientname); else client = strdup(clientname); ... if ((fd = open(clientname, O_RDONLY)) < 0) { return_null: free (client); return NULL; } The first if-statement determines whether the client (clientname) is a bare filename, and if so it invokes find_client to resolve it using $PATH. After this, "client" is either the original name ("clientname") or the resolved pathname. The second if-statement attempts to open the client file. It should use the result of the first if-statement, but instead uses the original parameter to the function. So if the parameter was a bare filename, it attempts to open it from the current directory instead of using the resolved pathame. The second if-statement should be: if ((fd = open(client, O_RDONLY)) < 0) { that is, using "client" rather than "clientname". I've tested this fix in my build of 3.16.0, and confirmed that the bug still exists in the current sources in git. STEPS TO REPRODUCE 1. Use a stock valgrind build on 64-bit x86-64 Linux. This will support both x86-64 and x86-32 platforms, defaulting to '64. 2. Build a trivial 32-bit C program in a subdirectory. For example: mkdir tmp echo 'int main(void) {return 0;}' > tmp/nop.c cc -o tmp/nop -m32 tmp/nop.c 3. Attempt to memgrind it (this must NOT be done in the directory containing the client, or you'll get a false negative): PATH=$PWD/tmp:$PATH valgrind -d nop You should get the wrong-platform message, and the debug output should include "no platform detected, defaulting platform to 'amd64-linux'". OBSERVED RESULT Valgrind fails because it's failing to detect the client platform. EXPECTED RESULT Valgrind should correctly open the client and detect the platform. (Run with higher debug levels, e.g. "-d -d", to see what select_platform is doing.) -- You are receiving this mail because: You are watching all bug changes.