Skip to content

Commit 22d82cf

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 23fafc1 commit 22d82cf

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
@@ -9,6 +9,7 @@
99
#include <sys/socket.h>
1010

1111
#include <algorithm>
12+
#include <iostream>
1213
#include <sstream>
1314
#include <string>
1415

@@ -2028,24 +2029,29 @@ static void inject_ld_helper_library(vector<string>& env,
20282029
}
20292030

20302031
void strip_outer_ld_preload(vector<string>& env) {
2031-
auto env_assignment = "LD_PRELOAD=";
2032+
string env_assignment = "LD_PRELOAD=";
20322033
auto it = env.begin();
20332034
for (; it != env.end(); ++it) {
20342035
if (it->find(env_assignment) != 0) {
20352036
continue;
20362037
}
2037-
size_t colon_pos = it->find(":");
2038-
if (colon_pos != string::npos) {
2039-
// If the preload library is loaded at all, it must be first
2040-
size_t preload_pos = it->find("librrpreload");
2041-
if (preload_pos < colon_pos) {
2042-
string new_ld_preload = it->substr(++colon_pos);
2043-
*it = env_assignment + new_ld_preload;
2044-
return;
2045-
} else {
2046-
DEBUG_ASSERT(preload_pos == string::npos);
2038+
istringstream st = istringstream(it->substr(env_assignment.length()));
2039+
string new_ld_preload;
2040+
string lib;
2041+
while (getline(st, lib, ':')) {
2042+
if (lib.empty()) {
2043+
continue;
20472044
}
2045+
if (lib.find("librrpreload") != string::npos) {
2046+
continue;
2047+
}
2048+
if (!new_ld_preload.empty()) {
2049+
new_ld_preload += ":";
2050+
}
2051+
new_ld_preload += lib;
20482052
}
2053+
*it = env_assignment + new_ld_preload;
2054+
return;
20492055
}
20502056
}
20512057

0 commit comments

Comments
 (0)