diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-02-19 12:25:40 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-07-02 09:54:19 +0200 |
| commit | c19a54fb02ed692d763d00b16efac752d19d56cc (patch) | |
| tree | 4d2c17abb6fdedb6d5e5105f58216e7918b9b301 | |
| parent | f7a2e49ab032a70c0ce18ff359edb15f0668ec4c (diff) | |
| download | mullvadvpn-c19a54fb02ed692d763d00b16efac752d19d56cc.tar.xz mullvadvpn-c19a54fb02ed692d763d00b16efac752d19d56cc.zip | |
Handle unknown event IDs gracefully
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/driver.rs | 26 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/mod.rs | 8 |
2 files changed, 27 insertions, 7 deletions
diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index 89b2e70429..3a9f4e1eb2 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -90,6 +90,8 @@ pub enum EventId { // ErrorFlag = 0x80000000, ErrorStartSplittingProcess = 0x80000001, ErrorStopSplittingProcess, + + Unknown, } pub enum EventBody { @@ -542,9 +544,20 @@ struct SplittingErrorEventHeader { image_name_length: u16, } -pub fn parse_event_buffer(buffer: &Vec<u8>) -> (EventId, EventBody) { - let mut event_header: EventHeader = unsafe { mem::zeroed() }; +pub fn parse_event_buffer(buffer: &Vec<u8>) -> Option<(EventId, EventBody)> { + let mut raw_event_id = 0u32; + unsafe { + ptr::copy_nonoverlapping( + &buffer[0], + &mut raw_event_id as *mut _ as *mut u8, + mem::size_of::<u32>(), + ) + }; + if raw_event_id >= EventId::Unknown as u32 { + return None; + } + let mut event_header: EventHeader = unsafe { mem::zeroed() }; unsafe { ptr::copy_nonoverlapping( &buffer[0], @@ -579,14 +592,14 @@ pub fn parse_event_buffer(buffer: &Vec<u8>) -> (EventId, EventBody) { ) }; - ( + Some(( event_header.event_id, EventBody::SplittingEvent { process_id: event.process_id, reason: event.reason, image: OsStringExt::from_wide(&image_name), }, - ) + )) } EventId::ErrorStartSplittingProcess | EventId::ErrorStopSplittingProcess => { let mut event: SplittingErrorEventHeader = unsafe { mem::zeroed() }; @@ -613,14 +626,15 @@ pub fn parse_event_buffer(buffer: &Vec<u8>) -> (EventId, EventBody) { ) }; - ( + Some(( event_header.event_id, EventBody::SplittingError { process_id: event.process_id, image: OsStringExt::from_wide(&image_name), }, - ) + )) } + EventId::Unknown => None, } } diff --git a/talpid-core/src/split_tunnel/windows/mod.rs b/talpid-core/src/split_tunnel/windows/mod.rs index a5ad4d5923..3d5efee414 100644 --- a/talpid-core/src/split_tunnel/windows/mod.rs +++ b/talpid-core/src/split_tunnel/windows/mod.rs @@ -163,7 +163,12 @@ impl SplitTunnel { unsafe { data_buffer.set_len(returned_bytes as usize) }; - let (event_id, event_body) = driver::parse_event_buffer(&data_buffer); + let event = driver::parse_event_buffer(&data_buffer); + + let (event_id, event_body) = match event { + Some((event_id, event_body)) => (event_id, event_body), + None => continue, + }; let event_str = match &event_id { EventId::StartSplittingProcess | EventId::ErrorStartSplittingProcess => { @@ -172,6 +177,7 @@ impl SplitTunnel { EventId::StopSplittingProcess | EventId::ErrorStopSplittingProcess => { "Stop splitting process" } + _ => "Unknown event ID", }; match event_body { |
