diff options
| -rw-r--r-- | talpid-wireguard/src/wireguard_go/mod.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/talpid-wireguard/src/wireguard_go/mod.rs b/talpid-wireguard/src/wireguard_go/mod.rs index 73b22a452f..6e082870f4 100644 --- a/talpid-wireguard/src/wireguard_go/mod.rs +++ b/talpid-wireguard/src/wireguard_go/mod.rs @@ -761,12 +761,16 @@ mod logging { use std::ffi::c_char; // Callback that receives messages from WireGuard + // + // # Safety + // - `msg` must be a valid pointer to a null-terminated UTF-8 string. pub unsafe extern "system" fn wg_go_logging_callback( level: WgLogLevel, msg: *const c_char, context: u64, ) { let managed_msg = if !msg.is_null() { + // SAFETY: caller promises that the pointer is valid. unsafe { std::ffi::CStr::from_ptr(msg).to_string_lossy().to_string() } } else { "Logging message from WireGuard is NULL".to_string() |
