From 1ac8b88326266b5ada346d725b478a725cf712dd Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Mon, 9 Jan 2023 11:32:53 +0100 Subject: [PATCH 1/3] Appease clippy --- src/bin/test.rs | 2 +- src/dir_section.rs | 6 +++--- src/linux/minidump_writer.rs | 4 ++-- src/linux/sections/exception_stream.rs | 4 ++-- src/linux/sections/thread_list_stream.rs | 6 +++--- src/mem_writer.rs | 2 +- tests/ptrace_dumper.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bin/test.rs b/src/bin/test.rs index 195640fc..08a98618 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -88,7 +88,7 @@ mod linux { fn test_file_id() -> Result<()> { let ppid = getppid().as_raw(); let exe_link = format!("/proc/{}/exe", ppid); - let exe_name = std::fs::read_link(&exe_link)?.into_os_string(); + let exe_name = std::fs::read_link(exe_link)?.into_os_string(); let mut dumper = PtraceDumper::new(getppid().as_raw())?; let mut found_exe = None; for (idx, mapping) in dumper.mappings.iter().enumerate() { diff --git a/src/dir_section.rs b/src/dir_section.rs index 63b2e39c..ced5a2d1 100644 --- a/src/dir_section.rs +++ b/src/dir_section.rs @@ -2,7 +2,7 @@ use crate::{ mem_writer::{Buffer, MemoryArrayWriter, MemoryWriterError}, minidump_format::MDRawDirectory, }; -use std::io::{Error, Seek, SeekFrom, Write}; +use std::io::{Error, Seek, Write}; pub type DumpBuf = Buffer; @@ -44,7 +44,7 @@ where Ok(Self { curr_idx: 0, section: dir_section, - destination_start_offset: destination.seek(SeekFrom::Current(0))?, + destination_start_offset: destination.stream_position()?, destination, last_position_written_to_file: 0, }) @@ -65,7 +65,7 @@ where // Now write it to file // First get all the positions - let curr_file_pos = self.destination.seek(SeekFrom::Current(0))?; + let curr_file_pos = self.destination.stream_position()?; let idx_pos = self.section.location_of_index(self.curr_idx); self.curr_idx += 1; diff --git a/src/linux/minidump_writer.rs b/src/linux/minidump_writer.rs index ea42ee7b..606a8590 100644 --- a/src/linux/minidump_writer.rs +++ b/src/linux/minidump_writer.rs @@ -156,7 +156,7 @@ impl MinidumpWriter { return true; } - let (stack_ptr, stack_len) = match dumper.get_stack_info(stack_pointer as usize) { + let (stack_ptr, stack_len) = match dumper.get_stack_info(stack_pointer) { Ok(x) => x, Err(_) => { return false; @@ -173,7 +173,7 @@ impl MinidumpWriter { } }; - let sp_offset = stack_pointer as usize - stack_ptr; + let sp_offset = stack_pointer - stack_ptr; self.principal_mapping .as_ref() .unwrap() diff --git a/src/linux/sections/exception_stream.rs b/src/linux/sections/exception_stream.rs index ad929014..f7edda8d 100644 --- a/src/linux/sections/exception_stream.rs +++ b/src/linux/sections/exception_stream.rs @@ -8,9 +8,9 @@ pub fn write( ) -> Result { let exception = if let Some(context) = &config.crash_context { MDException { - exception_code: context.inner.siginfo.ssi_signo as u32, + exception_code: context.inner.siginfo.ssi_signo, exception_flags: context.inner.siginfo.ssi_code as u32, - exception_address: context.inner.siginfo.ssi_addr as u64, + exception_address: context.inner.siginfo.ssi_addr, ..Default::default() } } else { diff --git a/src/linux/sections/thread_list_stream.rs b/src/linux/sections/thread_list_stream.rs index 0e952e87..11e625d0 100644 --- a/src/linux/sections/thread_list_stream.rs +++ b/src/linux/sections/thread_list_stream.rs @@ -74,8 +74,8 @@ pub fn write( // unhelpful. if config.crash_context.is_some() && thread.thread_id == config.blamed_thread as u32 { let crash_context = config.crash_context.as_ref().unwrap(); - let instruction_ptr = crash_context.get_instruction_pointer() as usize; - let stack_pointer = crash_context.get_stack_pointer() as usize; + let instruction_ptr = crash_context.get_instruction_pointer(); + let stack_pointer = crash_context.get_stack_pointer(); fill_thread_stack( config, buffer, @@ -142,7 +142,7 @@ pub fn write( } else { MaxStackLen::None // default to no maximum for this thread }; - let instruction_ptr = info.get_instruction_pointer() as usize; + let instruction_ptr = info.get_instruction_pointer(); fill_thread_stack( config, buffer, diff --git a/src/mem_writer.rs b/src/mem_writer.rs index 25c6a59f..a703d2b1 100644 --- a/src/mem_writer.rs +++ b/src/mem_writer.rs @@ -118,7 +118,7 @@ where let position = buffer.reserve(size) as u32; Ok(Self { - position: position as u32, + position, size, phantom: std::marker::PhantomData, }) diff --git a/tests/ptrace_dumper.rs b/tests/ptrace_dumper.rs index 29426805..a69631c5 100644 --- a/tests/ptrace_dumper.rs +++ b/tests/ptrace_dumper.rs @@ -255,7 +255,7 @@ fn test_sanitize_stack_copy() { } // The instruction pointer definitely should point into an executable mapping. - let instr_ptr = thread_info.get_instruction_pointer() as usize; + let instr_ptr = thread_info.get_instruction_pointer(); let mapping_info = dumper .find_mapping_no_bias(instr_ptr) .expect("Failed to find mapping info"); From c5c9c06e322dab7633c7fbf0d8d2d7a115a768c5 Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Tue, 28 Feb 2023 15:17:56 +0100 Subject: [PATCH 2/3] Check the note names when looking for the GNU build ID on Linux This fixes issue #73 --- src/linux/ptrace_dumper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linux/ptrace_dumper.rs b/src/linux/ptrace_dumper.rs index 12014464..30a4d368 100644 --- a/src/linux/ptrace_dumper.rs +++ b/src/linux/ptrace_dumper.rs @@ -481,14 +481,14 @@ impl PtraceDumper { ) -> Option<&'data [u8]> { if let Some(mut notes) = elf_obj.iter_note_headers(mem_slice) { while let Some(Ok(note)) = notes.next() { - if note.n_type == elf::note::NT_GNU_BUILD_ID { + if (note.name == "GNU") && (note.n_type == elf::note::NT_GNU_BUILD_ID) { return Some(note.desc); } } } if let Some(mut notes) = elf_obj.iter_note_sections(mem_slice, Some(".note.gnu.build-id")) { while let Some(Ok(note)) = notes.next() { - if note.n_type == elf::note::NT_GNU_BUILD_ID { + if (note.name == "GNU") && (note.n_type == elf::note::NT_GNU_BUILD_ID) { return Some(note.desc); } } From 11f87b155d6e2232372a01fb30b2b07912eb6bec Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Tue, 28 Feb 2023 15:47:03 +0100 Subject: [PATCH 3/3] Fix Windows builds by adding a missing winapi option --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 85f29ab2..0d16cd7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ mach2 = "0.4" # due to massive version churn [target.'cfg(target_os = "windows")'.dependencies.winapi] version = "0.3" -features = ["minwindef", "processthreadsapi", "winnt"] +features = ["handleapi", "minwindef", "processthreadsapi", "winnt"] [dev-dependencies] # Minidump-processor is async so we need an executor