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

validate whether addr is null before constructing slice #194

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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
6 changes: 3 additions & 3 deletions src/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct UnresolvedFrames {
pub frames: SmallVec<[<TraceImpl as Trace>::Frame; MAX_DEPTH]>,
pub thread_name: [u8; MAX_THREAD_NAME],
pub thread_name_length: usize,
pub thread_id: u64,
pub thread_id: libc::pthread_t,
pub sample_timestamp: SystemTime,
}

Expand All @@ -45,7 +45,7 @@ impl UnresolvedFrames {
pub fn new(
frames: SmallVec<[<TraceImpl as Trace>::Frame; MAX_DEPTH]>,
tn: &[u8],
thread_id: u64,
thread_id: libc::pthread_t,
sample_timestamp: SystemTime,
) -> Self {
let thread_name_length = tn.len();
Expand Down Expand Up @@ -168,7 +168,7 @@ impl Hash for Symbol {
pub struct Frames {
pub frames: Vec<Vec<Symbol>>,
pub thread_name: String,
pub thread_id: u64,
pub thread_id: libc::pthread_t,
pub sample_timestamp: SystemTime,
}

Expand Down
4 changes: 2 additions & 2 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ extern "C" fn perf_signal_handler(
write_thread_name(current_thread, &mut name);

let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) };
profiler.sample(bt, name.to_bytes(), current_thread as u64, sample_timestamp);
profiler.sample(bt, name.to_bytes(), current_thread, sample_timestamp);
}
}
}
Expand Down Expand Up @@ -455,7 +455,7 @@ impl Profiler {
&mut self,
backtrace: SmallVec<[<TraceImpl as Trace>::Frame; MAX_DEPTH]>,
thread_name: &[u8],
thread_id: u64,
thread_id: libc::pthread_t,
sample_timestamp: SystemTime,
) {
let frames = UnresolvedFrames::new(backtrace, thread_name, thread_id, sample_timestamp);
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