]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
SMB: use String::from_utf8_lossy in logging functions
authorPierre Chifflier <chifflier@wzdftpd.net>
Thu, 15 Mar 2018 07:16:24 +0000 (08:16 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 16 Mar 2018 11:25:36 +0000 (12:25 +0100)
rust/src/smb/log.rs

index ded03ef4529903331203e9ba0b1a69283e4cbd52..12d2af9dd91e1c2d67de357d2ee1e70b191a55e8 100644 (file)
@@ -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);
                 },