Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fail on malformed certificate table parsing #417

Merged
merged 7 commits into from
Jan 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/pe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

// TODO: panics with unwrap on None for apisetschema.dll, fhuxgraphics.dll and some others

use core::cmp::max;

use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec::Vec;
use core::cmp::max;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised by these import changes, did the formatter do this?


use log::debug;
use log::warn;
use scroll::{ctx, Pwrite};

use crate::container;
use crate::error;
use crate::pe::utils::pad;
use crate::strtab;

pub mod authenticode;
pub mod certificate_table;
Expand All @@ -29,15 +36,6 @@ pub mod symbol;
pub mod tls;
pub mod utils;

use crate::container;
use crate::error;
use crate::pe::utils::pad;
use crate::strtab;

use scroll::{ctx, Pwrite};

use log::debug;

#[derive(Debug)]
/// An analyzed PE32/PE32+ binary
pub struct PE<'a> {
Expand Down Expand Up @@ -142,7 +140,7 @@ impl<'a> PE<'a> {
return Err(error::Error::Malformed(format!(
"Unsupported header magic ({:#x})",
magic
)))
)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here too, this is also surprising to me

}
};

Expand Down Expand Up @@ -268,7 +266,11 @@ impl<'a> PE<'a> {
bytes,
certificate_table.virtual_address,
certificate_table.size,
)?;
)
.unwrap_or_else(|err| {
warn!("Cannot parse CertificateTable: {:?}", err);
Default::default()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, what is a default certificate directory in this case? is it going to cause other problems further down the line when parsing, or if a user accesses parts of it, will it panic? Does it have offsets into other parts of the PE file that are no longer valid, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default is empty table (no certificates), so no wrong offsets there

});

certificate_table.size as usize
} else {
Expand Down
Loading