Skip to content

Commit

Permalink
validate whether addr is null before constructing slice
Browse files Browse the repository at this point in the history
Signed-off-by: YangKeao <[email protected]>
  • Loading branch information
YangKeao committed Jan 19, 2023
1 parent b771d52 commit 851d881
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/addr_validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ fn open_pipe() -> nix::Result<()> {
}

pub fn validate(addr: *const libc::c_void) -> bool {
if addr.is_null() {
return false;
}

const CHECK_LENGTH: usize = 2 * size_of::<*const libc::c_void>() / size_of::<u8>();

// read data in the pipe
Expand Down
2 changes: 1 addition & 1 deletion src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Bucket<T: 'static> {

impl<T: Eq + Default> Default for Bucket<T> {
fn default() -> Bucket<T> {
let entries = Box::new(Default::default());
let entries = Box::default();

Self { length: 0, entries }
}
Expand Down
2 changes: 1 addition & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ mod protobuf {
/// `pprof` will generate google's pprof format report.
pub fn pprof(&self) -> crate::Result<protos::Profile> {
let mut dedup_str = HashSet::new();
for key in self.data.iter().map(|(key, _)| key) {
for key in self.data.keys() {
dedup_str.insert(key.thread_name_or_id());
for frame in key.frames.iter() {
for symbol in frame {
Expand Down

0 comments on commit 851d881

Please sign in to comment.