Skip to content

Commit

Permalink
insert sockets even if envp is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
meowjesty committed Jul 23, 2024
1 parent ccf2232 commit 6d7adc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mirrord/layer/src/detour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ impl<S> Detour<S> {
Detour::Error(e) => op(e),
}
}

#[inline]
pub fn or_bypass<O: FnOnce(Bypass) -> Detour<S>>(self, op: O) -> Detour<S> {
match self {
Detour::Success(s) => Detour::Success(s),
Detour::Bypass(b) => op(b),
Detour::Error(e) => Detour::Error(e),
}
}
}

impl<S> Detour<S>
Expand Down
6 changes: 5 additions & 1 deletion mirrord/layer/src/exec_hooks/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ fn shared_sockets() -> Vec<(i32, UserSocket)> {
)
)]
pub(crate) fn execve(env_vars: Detour<Argv>) -> Detour<*const *const c_char> {
let mut env_vars = env_vars?;
let mut env_vars = env_vars.or_bypass(|x| match x {
crate::detour::Bypass::EmptyOption => Detour::Success(Argv(Vec::new())),
other => Detour::Bypass(other),
})?;

let encoded = bincode::encode_to_vec(shared_sockets(), bincode::config::standard())
.map(|bytes| BASE64_URL_SAFE.encode(bytes))?;

Expand Down
4 changes: 2 additions & 2 deletions mirrord/layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ fn layer_start(mut config: LayerConfig) {

let _detour_guard = DetourGuard::new();
tracing::info!("Initializing mirrord-layer!");
tracing::trace!(
tracing::debug!(
executable = ?EXECUTABLE_PATH.get(),
args = ?EXECUTABLE_ARGS.get(),
pid = std::process::id(),
parent_pid = parent_id(),
env_vars = ?std::env::vars().count(),
env_vars = ?std::env::vars(),
"Loaded into executable",
);

Expand Down

0 comments on commit 6d7adc0

Please sign in to comment.