From c207cfc67ef0dd706bff152c7e54f1fc27a9ce9e Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 17 Jan 2025 12:17:27 -0600 Subject: [PATCH] rust/detect: remove nested unsafe around keyword registration Just a cleanup, I'm not sure why Rust wasn't warning on these nested/unneeded unsafe's. --- rust/src/detect/transforms/casechange.rs | 16 ++++------ .../detect/transforms/compress_whitespace.rs | 8 ++--- rust/src/detect/transforms/hash.rs | 30 ++++++++----------- rust/src/detect/transforms/http_headers.rs | 16 ++++------ rust/src/detect/transforms/urldecode.rs | 8 ++--- 5 files changed, 30 insertions(+), 48 deletions(-) diff --git a/rust/src/detect/transforms/casechange.rs b/rust/src/detect/transforms/casechange.rs index 80b6b82a48ac..c719ef154698 100644 --- a/rust/src/detect/transforms/casechange.rs +++ b/rust/src/detect/transforms/casechange.rs @@ -84,11 +84,9 @@ pub unsafe extern "C" fn DetectTransformToLowerRegister() { Free: None, TransformValidate: Some(tolower_validate), }; - unsafe { - G_TRANSFORM_TOLOWER_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_TOLOWER_ID < 0 { - SCLogWarning!("Failed registering transform tolower"); - } + G_TRANSFORM_TOLOWER_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_TOLOWER_ID < 0 { + SCLogWarning!("Failed registering transform tolower"); } } @@ -149,11 +147,9 @@ pub unsafe extern "C" fn DetectTransformToUpperRegister() { Free: None, TransformValidate: Some(toupper_validate), }; - unsafe { - G_TRANSFORM_TOUPPER_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_TOUPPER_ID < 0 { - SCLogWarning!("Failed registering transform toupper"); - } + G_TRANSFORM_TOUPPER_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_TOUPPER_ID < 0 { + SCLogWarning!("Failed registering transform toupper"); } } diff --git a/rust/src/detect/transforms/compress_whitespace.rs b/rust/src/detect/transforms/compress_whitespace.rs index ada86a7516ab..3e97e46c1831 100644 --- a/rust/src/detect/transforms/compress_whitespace.rs +++ b/rust/src/detect/transforms/compress_whitespace.rs @@ -107,11 +107,9 @@ pub unsafe extern "C" fn DetectTransformCompressWhitespaceRegister() { Free: None, TransformValidate: Some(compress_whitespace_validate), }; - unsafe { - G_TRANSFORM_COMPRESS_WHITESPACE_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_COMPRESS_WHITESPACE_ID < 0 { - SCLogWarning!("Failed registering transform compress_whitespace"); - } + G_TRANSFORM_COMPRESS_WHITESPACE_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_COMPRESS_WHITESPACE_ID < 0 { + SCLogWarning!("Failed registering transform compress_whitespace"); } } diff --git a/rust/src/detect/transforms/hash.rs b/rust/src/detect/transforms/hash.rs index 087427efee03..1b947178030d 100644 --- a/rust/src/detect/transforms/hash.rs +++ b/rust/src/detect/transforms/hash.rs @@ -39,7 +39,7 @@ const SC_MD5_LEN: usize = 16; unsafe extern "C" fn md5_setup( _de: *mut c_void, s: *mut c_void, _raw: *const std::os::raw::c_char, ) -> c_int { - if unsafe { G_DISABLE_HASHING } { + if G_DISABLE_HASHING { SCLogError!("MD5 hashing has been disabled, needed for to_md5 keyword"); return -1; } @@ -83,11 +83,9 @@ pub unsafe extern "C" fn DetectTransformMd5Register() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_MD5_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_MD5_ID < 0 { - SCLogWarning!("Failed registering transform md5"); - } + G_TRANSFORM_MD5_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_MD5_ID < 0 { + SCLogWarning!("Failed registering transform md5"); } } @@ -95,7 +93,7 @@ pub unsafe extern "C" fn DetectTransformMd5Register() { unsafe extern "C" fn sha1_setup( _de: *mut c_void, s: *mut c_void, _raw: *const std::os::raw::c_char, ) -> c_int { - if unsafe { G_DISABLE_HASHING } { + if G_DISABLE_HASHING { SCLogError!("SHA1 hashing has been disabled, needed for to_sha1 keyword"); return -1; } @@ -139,11 +137,9 @@ pub unsafe extern "C" fn DetectTransformSha1Register() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_SHA1_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_SHA1_ID < 0 { - SCLogWarning!("Failed registering transform sha1"); - } + G_TRANSFORM_SHA1_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_SHA1_ID < 0 { + SCLogWarning!("Failed registering transform sha1"); } } @@ -151,7 +147,7 @@ pub unsafe extern "C" fn DetectTransformSha1Register() { unsafe extern "C" fn sha256_setup( _de: *mut c_void, s: *mut c_void, _raw: *const std::os::raw::c_char, ) -> c_int { - if unsafe { G_DISABLE_HASHING } { + if G_DISABLE_HASHING { SCLogError!("SHA256 hashing has been disabled, needed for to_sha256 keyword"); return -1; } @@ -195,11 +191,9 @@ pub unsafe extern "C" fn DetectTransformSha256Register() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_SHA256_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_SHA256_ID < 0 { - SCLogWarning!("Failed registering transform sha256"); - } + G_TRANSFORM_SHA256_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_SHA256_ID < 0 { + SCLogWarning!("Failed registering transform sha256"); } } diff --git a/rust/src/detect/transforms/http_headers.rs b/rust/src/detect/transforms/http_headers.rs index 652765375941..de40c83198cf 100644 --- a/rust/src/detect/transforms/http_headers.rs +++ b/rust/src/detect/transforms/http_headers.rs @@ -86,11 +86,9 @@ pub unsafe extern "C" fn DetectTransformHeaderLowercaseRegister() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_HEADER_LOWER_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_HEADER_LOWER_ID < 0 { - SCLogWarning!("Failed registering transform tolower"); - } + G_TRANSFORM_HEADER_LOWER_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_HEADER_LOWER_ID < 0 { + SCLogWarning!("Failed registering transform tolower"); } } @@ -152,11 +150,9 @@ pub unsafe extern "C" fn DetectTransformStripPseudoHeadersRegister() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_STRIP_PSEUDO_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_STRIP_PSEUDO_ID < 0 { - SCLogWarning!("Failed registering transform toupper"); - } + G_TRANSFORM_STRIP_PSEUDO_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_STRIP_PSEUDO_ID < 0 { + SCLogWarning!("Failed registering transform toupper"); } } diff --git a/rust/src/detect/transforms/urldecode.rs b/rust/src/detect/transforms/urldecode.rs index deceb3be044e..6359382d72c0 100644 --- a/rust/src/detect/transforms/urldecode.rs +++ b/rust/src/detect/transforms/urldecode.rs @@ -121,11 +121,9 @@ pub unsafe extern "C" fn DetectTransformUrlDecodeRegister() { Free: None, TransformValidate: None, }; - unsafe { - G_TRANSFORM_URL_DECODE_ID = DetectHelperTransformRegister(&kw); - if G_TRANSFORM_URL_DECODE_ID < 0 { - SCLogWarning!("Failed registering transform dot_prefix"); - } + G_TRANSFORM_URL_DECODE_ID = DetectHelperTransformRegister(&kw); + if G_TRANSFORM_URL_DECODE_ID < 0 { + SCLogWarning!("Failed registering transform dot_prefix"); } }