Skip to content

Commit

Permalink
Replace non-binding if-let and let-else with simpler structures
Browse files Browse the repository at this point in the history
  • Loading branch information
sammko committed Mar 6, 2022
1 parent 606dbb1 commit 45038f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bakatsugi-injector/src/inspection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn get_dlopen_vmaddr(pid: Pid) -> Result<u64> {
// glibc 2.34 removes __libc_dlopen_mode but instead
// libdl is merged in, including normal dlopen. Same signature,
// don't care which one it is.
if let Some("__libc_dlopen_mode" | "dlopen") = name {
if matches!(name, Some("__libc_dlopen_mode" | "dlopen")) {
return Ok(sym.st_value - map.offset as u64 + map.start() as u64);
}
}
Expand Down
16 changes: 12 additions & 4 deletions bakatsugi-injector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,27 @@ fn handle_stage2(socket: &mut UnixStream, patchlib: &Path, debugelf: Option<&Pat
let patches = parse_patchspec(&patchelf).context("Could not parse patchspec")?;

MessageItoT::Ping(33).send(socket)?;
let MessageTtoI::Pong(33) = MessageTtoI::recv(socket)? else { bail!("BAD") };
if MessageTtoI::recv(socket)? != MessageTtoI::Pong(33) {
bail!("Invalid response from target stage2");
}

MessageItoT::RecvDSO(1).send(socket)?;
send_fd(patchfd.as_raw_fd(), socket)?;
drop(patchfd);

let MessageTtoI::Ok = MessageTtoI::recv(socket)? else { bail!("BAD") };
if MessageTtoI::recv(socket)? != MessageTtoI::Ok {
bail!("Invalid response from target stage2");
}

if let Some(debugpath) = debugelf {
MessageItoT::RecvDebugElf.send(socket)?;
let debugfd = fs::File::open(debugpath)?;
send_fd(debugfd.as_raw_fd(), socket)?;
drop(debugfd);

let MessageTtoI::Ok = MessageTtoI::recv(socket)? else { bail!("BAD") };
if MessageTtoI::recv(socket)? != MessageTtoI::Ok {
bail!("Invalid response from target stage2");
}
}

for patch in patches {
Expand All @@ -191,7 +197,9 @@ fn handle_stage2(socket: &mut UnixStream, patchlib: &Path, debugelf: Option<&Pat
}
}
.send(socket)?;
let MessageTtoI::Ok = MessageTtoI::recv(socket)? else { bail!("BAD") };
if MessageTtoI::recv(socket)? != MessageTtoI::Ok {
bail!("Invalid response from target stage2");
}
}

MessageItoT::Quit.send(socket)?;
Expand Down
4 changes: 2 additions & 2 deletions bakatsugi-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bincode::{
Decode, Encode,
};

#[derive(Encode, Decode, Debug)]
#[derive(PartialEq, Eq, Encode, Decode, Debug)]
pub enum MessageItoT {
Ping(u64),
OpenDSO(i32, PathBuf),
Expand All @@ -17,7 +17,7 @@ pub enum MessageItoT {
Quit,
}

#[derive(Encode, Decode, Debug)]
#[derive(PartialEq, Eq, Encode, Decode, Debug)]
pub enum MessageTtoI {
Pong(u64),
Ok,
Expand Down

0 comments on commit 45038f4

Please sign in to comment.