From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- toolkit/crashreporter/mozwer-rust/Cargo.toml | 5 ++++- toolkit/crashreporter/mozwer-rust/lib.rs | 31 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'toolkit/crashreporter/mozwer-rust') diff --git a/toolkit/crashreporter/mozwer-rust/Cargo.toml b/toolkit/crashreporter/mozwer-rust/Cargo.toml index 561a10b015..89cf3d4356 100644 --- a/toolkit/crashreporter/mozwer-rust/Cargo.toml +++ b/toolkit/crashreporter/mozwer-rust/Cargo.toml @@ -7,7 +7,9 @@ license = "MPL-2.0" [dependencies] libc = "0.2.0" -mozilla-central-workspace-hack = { version = "0.1", features = ["mozwer_s"], optional = true } +mozilla-central-workspace-hack = { version = "0.1", features = [ + "mozwer_s", +], optional = true } process_reader = { path = "../process_reader/" } rust-ini = "0.10" serde = { version = "1.0", features = ["derive"] } @@ -23,6 +25,7 @@ features = [ "Win32_System_Com", "Win32_System_Diagnostics_Debug", "Win32_System_ErrorReporting", + "Win32_System_Memory", "Win32_System_ProcessStatus", "Win32_System_SystemInformation", "Win32_System_SystemServices", diff --git a/toolkit/crashreporter/mozwer-rust/lib.rs b/toolkit/crashreporter/mozwer-rust/lib.rs index 198a14a34b..61fc894462 100644 --- a/toolkit/crashreporter/mozwer-rust/lib.rs +++ b/toolkit/crashreporter/mozwer-rust/lib.rs @@ -9,7 +9,7 @@ use serde::Serialize; use serde_json::ser::to_writer; use std::convert::TryInto; use std::ffi::{c_void, OsString}; -use std::fs::{read_to_string, DirBuilder, File}; +use std::fs::{read_to_string, DirBuilder, File, OpenOptions}; use std::io::{BufRead, BufReader, Write}; use std::mem::{size_of, transmute, zeroed}; use std::os::windows::ffi::{OsStrExt, OsStringExt}; @@ -248,8 +248,9 @@ fn handle_main_process_crash( fn handle_child_process_crash(crash_report: CrashReport, child_process: HANDLE) -> Result<()> { let parent_process = get_parent_process(child_process)?; let process_reader = ProcessReader::new(parent_process).map_err(|_e| ())?; + let libxul_address = process_reader.find_module("xul.dll").map_err(|_e| ())?; let wer_notify_proc = process_reader - .find_section("xul.dll", "mozwerpt") + .find_section(libxul_address, b"mozwerpt") .map_err(|_e| ())?; let wer_notify_proc = unsafe { transmute::<_, LPTHREAD_START_ROUTINE>(wer_notify_proc) }; @@ -524,8 +525,7 @@ impl ApplicationInformation { let install_time = ApplicationInformation::get_install_time( &crash_reports_dir, &application_data.build_id, - ) - .unwrap_or("0".to_string()); + ); Ok(ApplicationInformation { install_path, @@ -596,10 +596,29 @@ impl ApplicationInformation { } } - fn get_install_time(crash_reports_path: &Path, build_id: &str) -> Result { + fn get_install_time(crash_reports_path: &Path, build_id: &str) -> String { let file_name = "InstallTime".to_owned() + build_id; let file_path = crash_reports_path.join(file_name); - read_to_string(file_path).map_err(|_e| ()) + + // If the file isn't present we'll attempt to atomically create it and + // populate it. This code essentially matches the corresponding code in + // nsExceptionHandler.cpp SetupExtraData(). + if let Ok(mut file) = OpenOptions::new() + .create_new(true) + .write(true) + .open(&file_path) + { + // SAFETY: No risks in calling `time()` with a null pointer. + let _ = write!(&mut file, "{}", unsafe { time(null_mut()) }.to_string()); + } + + // As a last resort, if we can't read the file we fall back to the + // current time. This might cause us to overstate the number of users + // affected by a crash, but given it's very unlikely to hit this particular + // path it won't be a problem. + // + // SAFETY: No risks in calling `time()` with a null pointer. + read_to_string(&file_path).unwrap_or(unsafe { time(null_mut()) }.to_string()) } } -- cgit v1.2.3