2 ms·
> It will also execute libc.so and libpcre.so from that folder. That's simply how libraries are loaded on both Linux and Windows That's true on Windows but NOT
by quietbritishjim 6y ago
> It will also execute libc.so and libpcre.so from that folder. That's simply how libraries are loaded on both Linux and Windows
That's true on Windows but NOT on Linux (which I actually find a bit annoying for deploying applications to users). On Linux you could explicitly add "." to your LD_LIBRARY_PATH variable but even then I think it would look in the working directory rather than the executable directory.
- dfox 6y agoAnd since XP SP2 windows by default searches current directory as one of the last places that it looks into. It is not exactly perfect mitigation but probably works for most instances of this issue.
- quietbritishjim 6y agoI think the main concern here is the directory containing the application (especially if it's in the downloads directory), which is always first in the search order on Windows [1]. There was an article in the Old New Thing blog about how this is because the application's directory is expected to be its own safe package, usually a subdirectory of Program Files. You're talking about the current working directory, which can be different, and you're right it was moved later in the search order in XP SP2 (also mentioned in [1]). I had no idea it was ever searched at all, so thanks for that! [1] https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-...
- account42 6y ago> which I actually find a bit annoying for deploying applications to users Linux ELF binaries can have a library search path embedded using the -rpath linker option. Inside that search path, '$ORIGIN' refers to the binary location so you can have the Windows behavior if you want to.
- quietbritishjim 6y agoAmazing, thanks! I already knew about the embedded -rpath but hadn't heard about $ORIGIN before so I always dismissed it as not being much use. According to this StackOverflow answer [1] you need to use the -z origin switch but I only found that thanks to you pointing me in the right direction. I'll be adding this particular gotcha to my deployed executables immediately! [1] https://stackoverflow.com/questions/6324131/rpath-origin-not-having-desired-effect https://stackoverflow.com/questions/6324131/rpath-origin-not...