From cf5de0c58e340435dfeeb95079f61757e1c4c950 Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Thu, 15 Mar 2018 08:16:24 +0100 Subject: [PATCH] SMB: use String::from_utf8_lossy in logging functions --- rust/src/smb/log.rs | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/rust/src/smb/log.rs b/rust/src/smb/log.rs index ded03ef452..12d2af9dd9 100644 --- a/rust/src/smb/log.rs +++ b/rust/src/smb/log.rs @@ -146,22 +146,13 @@ fn smb_common_header(state: &SMBState, tx: &SMBTransaction) -> Json Some(SMBTransactionTypeData::SESSIONSETUP(ref x)) => { if let Some(ref ntlmssp) = x.ntlmssp { let jsd = Json::object(); - let domain = match str::from_utf8(&ntlmssp.domain) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let domain = String::from_utf8_lossy(&ntlmssp.domain); jsd.set_string("domain", &domain); - let user = match str::from_utf8(&ntlmssp.user) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let user = String::from_utf8_lossy(&ntlmssp.user); jsd.set_string("user", &user); - let host = match str::from_utf8(&ntlmssp.host) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let host = String::from_utf8_lossy(&ntlmssp.host); jsd.set_string("host", &host); if let Some(ref v) = ntlmssp.version { @@ -185,15 +176,9 @@ fn smb_common_header(state: &SMBState, tx: &SMBTransaction) -> Json match x.request_host { Some(ref r) => { let jsd = Json::object(); - let os = match str::from_utf8(&r.native_os) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let os = String::from_utf8_lossy(&r.native_os); jsd.set_string("native_os", &os); - let lm = match str::from_utf8(&r.native_lm) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let lm = String::from_utf8_lossy(&r.native_lm); jsd.set_string("native_lm", &lm); js.set("request", jsd); }, @@ -202,15 +187,9 @@ fn smb_common_header(state: &SMBState, tx: &SMBTransaction) -> Json match x.response_host { Some(ref r) => { let jsd = Json::object(); - let os = match str::from_utf8(&r.native_os) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let os = String::from_utf8_lossy(&r.native_os); jsd.set_string("native_os", &os); - let lm = match str::from_utf8(&r.native_lm) { - Ok(v) => v, - Err(_) => "UTF8_ERROR", - }; + let lm = String::from_utf8_lossy(&r.native_lm); jsd.set_string("native_lm", &lm); js.set("response", jsd); },