From 144af1f2f3e991726e38d0dfe8a8e7ce6ee3045e Mon Sep 17 00:00:00 2001 From: EKTehtris <86344566+EKTehtris@users.noreply.github.com> Date: Thu, 24 Jun 2021 13:59:43 +0200 Subject: [PATCH] fix: improve if/else with a match case --- aya/src/programs/uprobe.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/aya/src/programs/uprobe.rs b/aya/src/programs/uprobe.rs index b1085cf4..233a87ba 100644 --- a/aya/src/programs/uprobe.rs +++ b/aya/src/programs/uprobe.rs @@ -258,21 +258,23 @@ impl LdSoCache { ) )?; let mut is_old: bool = false; - if header != LD_SO_CACHE_HEADER { - if header != LD_SO_CACHE_HEADER_OLD { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "invalid ld.so.cache header", - )); - } else { + match header { + LD_SO_CACHE_HEADER => { + // we have to reset the position since we found the new header + cursor.set_position(LD_SO_CACHE_HEADER.len() as u64); + } + LD_SO_CACHE_HEADER_OLD => { is_old = true; // add a padding corresponding to LD_SO_CACHE_HEADER_OLD // size 11 + 1 to align on 12 bytes or 3*4 bounds cursor.consume(1) } - } else { - // we have to reset the position since we found the new header - cursor.set_position(LD_SO_CACHE_HEADER.len() as u64); + _ => { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "invalid ld.so.cache header", + )); + } } let num_entries: u32 = read_u32(&mut cursor)?;