Skip to content

Commit

Permalink
Changed strip_outer_ld_preload to remove librrpreload in any case.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bernhardu committed Jun 24, 2021
1 parent 9bb0ed5 commit 8c3344e
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/RecordSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/socket.h>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -2030,24 +2031,29 @@ static void inject_ld_helper_library(vector<string>& env,
}

void strip_outer_ld_preload(vector<string>& env) {
auto env_assignment = "LD_PRELOAD=";
string env_assignment = "LD_PRELOAD=";
auto it = env.begin();
for (; it != env.end(); ++it) {
if (it->find(env_assignment) != 0) {
continue;
}
size_t colon_pos = it->find(":");
if (colon_pos != string::npos) {
// If the preload library is loaded at all, it must be first
size_t preload_pos = it->find("librrpreload");
if (preload_pos < colon_pos) {
string new_ld_preload = it->substr(++colon_pos);
*it = env_assignment + new_ld_preload;
return;
} else {
DEBUG_ASSERT(preload_pos == string::npos);
istringstream st = istringstream(it->substr(env_assignment.length()));
string new_ld_preload;
string lib;
while (getline(st, lib, ':')) {
if (lib.empty()) {
continue;
}
if (lib.find("librrpreload") != string::npos) {
continue;
}
if (!new_ld_preload.empty()) {
new_ld_preload += ":";
}
new_ld_preload += lib;
}
*it = env_assignment + new_ld_preload;
return;
}
}

Expand Down

0 comments on commit 8c3344e

Please sign in to comment.