Bug 1624253 - Catch panic in mdns_service_generate_uuid; r=mjf

In rare cases, the random number generator can fail to initialize when
generating a v4 UUID, causing a panic and crash. This adds code to catch that
panic and return a nil (all zeros) UUID instead. Using a nil UUID seems better
from a user privacy perspective than failing to obfuscate the host address and
leaking it when it is expected to be hidden.

Longer term, we might want to switch over to using nsIUUIDGenerator, but that
would require changes to how the socket process is initialized.

Differential Revision: https://phabricator.services.mozilla.com/D70172

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2020-04-08 14:20:38 +00:00
Родитель 04fa714df4
Коммит b4a9997899
1 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -10,6 +10,7 @@ use std::ffi::{c_void, CStr, CString};
use std::io;
use std::net;
use std::os::raw::c_char;
use std::panic;
use std::sync::mpsc::channel;
use std::thread;
use std::time;
@ -614,8 +615,12 @@ pub unsafe extern "C" fn mdns_service_unregister_hostname(
#[no_mangle]
pub extern "C" fn mdns_service_generate_uuid() -> *const c_char {
let uuid = Uuid::new_v4().to_hyphenated().to_string();
match CString::new(uuid) {
let uuid = match panic::catch_unwind(|| Uuid::new_v4()) {
Ok(uuid) => uuid,
Err(_) => Uuid::nil(),
};
match CString::new(uuid.to_hyphenated().to_string()) {
Ok(uuid) => uuid.into_raw(),
Err(_) => unreachable!(), // UUID should not contain 0 byte
}