Skip to content

Commit 3abd886

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 9b6bf29 commit 3abd886

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

@@ -2036,24 +2037,29 @@ static void inject_ld_helper_library(vector<string>& env,
20362037
}
20372038

20382039
void strip_outer_ld_preload(vector<string>& env) {
2039-
auto env_assignment = "LD_PRELOAD=";
2040+
string env_assignment = "LD_PRELOAD=";
20402041
auto it = env.begin();
20412042
for (; it != env.end(); ++it) {
20422043
if (it->find(env_assignment) != 0) {
20432044
continue;
20442045
}
2045-
size_t colon_pos = it->find(":");
2046-
if (colon_pos != string::npos) {
2047-
// If the preload library is loaded at all, it must be first
2048-
size_t preload_pos = it->find("librrpreload");
2049-
if (preload_pos < colon_pos) {
2050-
string new_ld_preload = it->substr(++colon_pos);
2051-
*it = env_assignment + new_ld_preload;
2052-
return;
2053-
} else {
2054-
DEBUG_ASSERT(preload_pos == string::npos);
2046+
istringstream st = istringstream(it->substr(env_assignment.length()));
2047+
string new_ld_preload;
2048+
string lib;
2049+
while (getline(st, lib, ':')) {
2050+
if (lib.empty()) {
2051+
continue;
20552052
}
2053+
if (lib.find("librrpreload") != string::npos) {
2054+
continue;
2055+
}
2056+
if (!new_ld_preload.empty()) {
2057+
new_ld_preload += ":";
2058+
}
2059+
new_ld_preload += lib;
20562060
}
2061+
*it = env_assignment + new_ld_preload;
2062+
return;
20572063
}
20582064
}
20592065

0 commit comments

Comments
 (0)