Skip to content

Commit f8c949c

Browse files
committed
Changed strip_outer_ld_preload to remove librrpreload in any case.
In test nested_detach (with an asan enabled rr build) following assertion was hit because LD_PRELOAD contained libasan before librrpreload. RecordSession.cc:2047: void rr::strip_outer_ld_preload(std::vector<std::__cxx11::basic_string<char> >&): Assertion `preload_pos == string::npos' failed.
1 parent bd67798 commit f8c949c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/RecordSession.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sys/socket.h>
1111

1212
#include <algorithm>
13+
#include <iostream>
1314
#include <sstream>
1415
#include <string>
1516

@@ -2124,24 +2125,29 @@ static void inject_ld_helper_library(vector<string>& env,
21242125
}
21252126

21262127
void strip_outer_ld_preload(vector<string>& env) {
2127-
auto env_assignment = "LD_PRELOAD=";
2128+
string env_assignment = "LD_PRELOAD=";
21282129
auto it = env.begin();
21292130
for (; it != env.end(); ++it) {
21302131
if (it->find(env_assignment) != 0) {
21312132
continue;
21322133
}
2133-
size_t colon_pos = it->find(":");
2134-
if (colon_pos != string::npos) {
2135-
// If the preload library is loaded at all, it must be first
2136-
size_t preload_pos = it->find("librrpreload");
2137-
if (preload_pos < colon_pos) {
2138-
string new_ld_preload = it->substr(++colon_pos);
2139-
*it = env_assignment + new_ld_preload;
2140-
return;
2141-
} else {
2142-
DEBUG_ASSERT(preload_pos == string::npos);
2134+
istringstream st = istringstream(it->substr(env_assignment.length()));
2135+
string new_ld_preload;
2136+
string lib;
2137+
while (getline(st, lib, ':')) {
2138+
if (lib.empty()) {
2139+
continue;
21432140
}
2141+
if (lib.find("librrpreload") != string::npos) {
2142+
continue;
2143+
}
2144+
if (!new_ld_preload.empty()) {
2145+
new_ld_preload += ":";
2146+
}
2147+
new_ld_preload += lib;
21442148
}
2149+
*it = env_assignment + new_ld_preload;
2150+
return;
21452151
}
21462152
}
21472153

0 commit comments

Comments
 (0)