Skip to content

Commit

Permalink
rust/detect: remove nested unsafe around keyword registration
Browse files Browse the repository at this point in the history
Just a cleanup, I'm not sure why Rust wasn't warning on these
nested/unneeded unsafe's.
  • Loading branch information
jasonish authored and victorjulien committed Jan 17, 2025
1 parent 2bcc66d commit c207cfc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 48 deletions.
16 changes: 6 additions & 10 deletions rust/src/detect/transforms/casechange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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");
}
}

Expand Down
8 changes: 3 additions & 5 deletions rust/src/detect/transforms/compress_whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
30 changes: 12 additions & 18 deletions rust/src/detect/transforms/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -83,19 +83,17 @@ 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");
}
}

#[no_mangle]
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;
}
Expand Down Expand Up @@ -139,19 +137,17 @@ 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");
}
}

#[no_mangle]
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;
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
16 changes: 6 additions & 10 deletions rust/src/detect/transforms/http_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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");
}
}

Expand Down
8 changes: 3 additions & 5 deletions rust/src/detect/transforms/urldecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

0 comments on commit c207cfc

Please sign in to comment.