Skip to content

Commit de55da0

Browse files
committed
validate whether addr is null before constructing slice
Signed-off-by: YangKeao <[email protected]>
1 parent b771d52 commit de55da0

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

src/addr_validate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ fn open_pipe() -> nix::Result<()> {
5959
}
6060

6161
pub fn validate(addr: *const libc::c_void) -> bool {
62+
if addr.is_null() {
63+
return false;
64+
}
65+
6266
const CHECK_LENGTH: usize = 2 * size_of::<*const libc::c_void>() / size_of::<u8>();
6367

6468
// read data in the pipe

src/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Bucket<T: 'static> {
3737

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

4242
Self { length: 0, entries }
4343
}

src/profiler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ extern "C" fn perf_signal_handler(
358358
write_thread_name(current_thread, &mut name);
359359

360360
let name = unsafe { std::ffi::CStr::from_ptr(name_ptr) };
361-
profiler.sample(bt, name.to_bytes(), current_thread as u64, sample_timestamp);
361+
profiler.sample(bt, name.to_bytes(), current_thread, sample_timestamp);
362362
}
363363
}
364364
}

src/report.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ mod protobuf {
229229
/// `pprof` will generate google's pprof format report.
230230
pub fn pprof(&self) -> crate::Result<protos::Profile> {
231231
let mut dedup_str = HashSet::new();
232-
for key in self.data.iter().map(|(key, _)| key) {
232+
for key in self.data.keys() {
233233
dedup_str.insert(key.thread_name_or_id());
234234
for frame in key.frames.iter() {
235235
for symbol in frame {

0 commit comments

Comments
 (0)