Skip to content

Commit 31e1ce4

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 0404bcd commit 31e1ce4

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

@@ -2030,24 +2031,29 @@ static void inject_ld_helper_library(vector<string>& env,
20302031
}
20312032

20322033
void strip_outer_ld_preload(vector<string>& env) {
2033-
auto env_assignment = "LD_PRELOAD=";
2034+
string env_assignment = "LD_PRELOAD=";
20342035
auto it = env.begin();
20352036
for (; it != env.end(); ++it) {
20362037
if (it->find(env_assignment) != 0) {
20372038
continue;
20382039
}
2039-
size_t colon_pos = it->find(":");
2040-
if (colon_pos != string::npos) {
2041-
// If the preload library is loaded at all, it must be first
2042-
size_t preload_pos = it->find("librrpreload");
2043-
if (preload_pos < colon_pos) {
2044-
string new_ld_preload = it->substr(++colon_pos);
2045-
*it = env_assignment + new_ld_preload;
2046-
return;
2047-
} else {
2048-
DEBUG_ASSERT(preload_pos == string::npos);
2040+
istringstream st = istringstream(it->substr(env_assignment.length()));
2041+
string new_ld_preload;
2042+
string lib;
2043+
while (getline(st, lib, ':')) {
2044+
if (lib.empty()) {
2045+
continue;
20492046
}
2047+
if (lib.find("librrpreload") != string::npos) {
2048+
continue;
2049+
}
2050+
if (!new_ld_preload.empty()) {
2051+
new_ld_preload += ":";
2052+
}
2053+
new_ld_preload += lib;
20502054
}
2055+
*it = env_assignment + new_ld_preload;
2056+
return;
20512057
}
20522058
}
20532059

0 commit comments

Comments
 (0)