-
Notifications
You must be signed in to change notification settings - Fork 163
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
Changes from 1 commit
2c7f7b5
b46e266
872544b
ac97d4c
aa0de1b
8838feb
1f7cdc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
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; | ||
|
@@ -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> { | ||
|
@@ -142,7 +140,7 @@ impl<'a> PE<'a> { | |
return Err(error::Error::Malformed(format!( | ||
"Unsupported header magic ({:#x})", | ||
magic | ||
))) | ||
))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto here too, this is also surprising to me |
||
} | ||
}; | ||
|
||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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?