dlopen: Segfault due to overwriting .so file after it was loaded and loading it again
Konstantin Kharlamov
hi-angel@yandex.ru
Fri Nov 20 07:17:30 GMT 2020
On Fri, 2020-11-20 at 06:52 +0000, Wendeborn, Jonathan via Libc-help wrote:
> Hi,
>
> I am a C++ developer but usually programming and debugging on Windows (so
> please excuse any wrong terms). Now I'm compiling my program on Linux (gcc
> 9.3.0 on Debian Bullseye with Boost 1.70) for the first time and get a
> Segfault in my unit tests.
> Luckily I was able to write a reproducer and boil it down to my code
> overwriting the .so file after having it loaded (and unloaded):
I can't seem to reproduce it. I modified paths in your testcase as fololows:
#include <boost/filesystem/operations.hpp>
#include <boost/dll/shared_library.hpp>
#include <iostream>
void doit() {
boost::filesystem::copy_file("/tmp/libSomething.so", "/tmp/libSomething2.so", boost::filesystem::copy_option::overwrite_if_exists);
boost::dll::shared_library l;
std::cout << "pre load" << std::endl;
l.load("/tmp/libSomething2.so");
std::cout << "loaded" << std::endl;
}
int main() {
doit();
doit();
return 0;
}
And I build it with
g++ test.cpp -o a -g3 -O0 -Wall -Wextra -Wsign-conversion -std=c++17 -fsanitize=address -ldl -lboost_filesystem -lboost_system
Running it I get no segfault, just output:
λ ./a
pre load
loaded
pre load
loaded
Please try placing the lib into `/tmp/libSomething` and running the app, do you still see crash?
More information about the Libc-help
mailing list