runtime icon indicating copy to clipboard operation
runtime copied to clipboard

CoreRun tries to execute .exe from incorrect path.

Open myungjoo opened this issue 10 years ago • 5 comments

This was tested and observed at both ARM/Linux and x64/Linux.

Reproduction

  • Install coreclr & corefx at directory /A/
  • Install a.exe at directory /B/
  • Create another a.exe (different from /B/a.exe) at /A/ (for a more dramatic failure, create a null file, /A/a.exe)
  • At /A/, run ./corerun /B/a.exe

Expected

  • The file /B/a.exe is executed.

Result

  • The file /A/a.exe is executed.

Note that if /A/a.exe does not exist, it properly executed B/a.exe.

myungjoo avatar Jun 09 '16 07:06 myungjoo

I had similar issue.

I was playing with 'HelloWord' example trying to create some test but it was not working. Finally I took original 'HelloWord' example and just changed the message but on launch it printed original unmodified message. I even tried to change file name but it didn't help.

It printed new message only when I changed name of the 'class' in my modified 'HelloWord' example.

It helped me to find that I had 'HelloWord' application binary in directory with 'corerun'.

I suppose it worked in the following way: when I launched corerun_dir/corerun my_dir/my_app.exe, 'corerun' extracted name of the 'class' from my binary and started to load 'class' with than name but instead of using explicit path (my_dir/my_app.exe) specified in command line 'corerun' started to search for file with necessary 'class' name and found alternative file with different file name but with the same 'class' name in its own directory (corerun_dir).

mkborg avatar Jun 09 '16 08:06 mkborg

HRESULT AssemblyBinder::BindByTpaList(...)uses simpleName that extracts the filename from the full path, which later makes the fileName at line 1362 of the same function, to refer /A/a.exe, not /B/a.exe. (pTpaEntry->m_wszILFileName is incorrectly initialized)

This is a logic error in ``HRESULT AssemblyBinder::BindByTpaList`.

Another really fishy scheme is at AssemblyBinder::BindWhereRef() (src/binder/assemblybinder.cpp):

It first gets "assemblyName" from the "assemblyPath" (/B/a.exe), which results in a as the assemblyName. at Line 1006-1021.

Then, it retrieves the assembly based on the assemblyName, a, which results in searching for /A/a.exe before trying the original full path /B/a.exe.

The code around here is juggling around the path info too excessively while we do not support anything like GAC yet. :(

myungjoo avatar Jun 09 '16 08:06 myungjoo

A fix is being implemented by enforcing CLRPrivBinderCoreCLR::Bind()'s call to AssemblyBinder::BindAssembly() explicitly state that it MUST find the assembly in the given path.

This could be done by nullptr test of szCodeBase argument of AssemblyBinder::BindAssembly()

, which is supposed to do so by calling BindByName if it's null and BindWhereRef if it's not null.

However, in the current coreclr, it goes to BindByTpaList regardless of what's being intended.

myungjoo avatar Jun 10 '16 06:06 myungjoo

~~It look like the current commit of CoreCLR has this issue fixed. I'll verify if it's completely gone and close this afterwards.~~

Negative.

myungjoo avatar Jun 23 '16 11:06 myungjoo

The linked PR had some issues and wasn't completed, so this issu remains up for grabs.

danmoseley avatar Oct 20 '16 18:10 danmoseley