Skip to content

Commit

Permalink
Add missing UserAddrMeta -> blaze_user_addr_meta conversion
Browse files Browse the repository at this point in the history
We still had a todo!() in the code that could trigger when normalizing
an APK ELF file using the C APIs.
This change adds the necessary conversion to fix the potential panic.

Signed-off-by: Daniel Müller <[email protected]>
  • Loading branch information
d-e-s-o committed Sep 14, 2023
1 parent 658e6fe commit d80f592
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------
- Fixed potential panic when normalizing an APK ELF file using the C APIs


0.2.0-alpha.5
-------------
- Fixed potentially incorrect reporting of symbols from ELF source
Expand Down
19 changes: 18 additions & 1 deletion src/c_api/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ pub struct blaze_user_addr_meta {
impl From<UserAddrMeta> for blaze_user_addr_meta {
fn from(other: UserAddrMeta) -> Self {
match other {
UserAddrMeta::ApkElf(_apk) => todo!(),
UserAddrMeta::ApkElf(apk_elf) => Self {
kind: blaze_user_addr_meta_kind::BLAZE_USER_ADDR_APK_ELF,
variant: blaze_user_addr_meta_variant {
apk_elf: ManuallyDrop::new(blaze_user_addr_meta_apk_elf::from(apk_elf)),
},
},
UserAddrMeta::Elf(elf) => Self {
kind: blaze_user_addr_meta_kind::BLAZE_USER_ADDR_ELF,
variant: blaze_user_addr_meta_variant {
Expand Down Expand Up @@ -570,6 +575,10 @@ mod tests {

let unknown_new = Unknown::from(blaze_user_addr_meta_unknown::from(unknown.clone()));
assert_eq!(unknown_new, unknown);

let meta = UserAddrMeta::Unknown(unknown_new);
let meta_new = UserAddrMeta::from(blaze_user_addr_meta::from(meta.clone()));
assert_eq!(meta_new, meta);
}

/// Check that we can convert an [`ApkElf`] into a
Expand All @@ -595,6 +604,10 @@ mod tests {

let apk_new = ApkElf::from(blaze_user_addr_meta_apk_elf::from(apk.clone()));
assert_eq!(apk_new, apk);

let meta = UserAddrMeta::ApkElf(apk_new);
let meta_new = UserAddrMeta::from(blaze_user_addr_meta::from(meta.clone()));
assert_eq!(meta_new, meta);
}

/// Check that we can convert an [`Elf`] into a [`blaze_user_addr_meta_elf`]
Expand All @@ -609,5 +622,9 @@ mod tests {

let elf_new = Elf::from(blaze_user_addr_meta_elf::from(elf.clone()));
assert_eq!(elf_new, elf);

let meta = UserAddrMeta::Elf(elf_new);
let meta_new = UserAddrMeta::from(blaze_user_addr_meta::from(meta.clone()));
assert_eq!(meta_new, meta);
}
}

0 comments on commit d80f592

Please sign in to comment.