• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.73
/rust/src/detect/transforms/casechange.rs
1
/* Copyright (C) 2024 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
use crate::detect::SIGMATCH_NOOPT;
19
use suricata_sys::sys::{
20
    DetectEngineCtx, DetectEngineThreadCtx, InspectionBuffer, SCDetectHelperTransformRegister,
21
    SCDetectSignatureAddTransform, SCInspectionBufferCheckAndExpand, SCInspectionBufferTruncate,
22
    SCTransformTableElmt, Signature,
23
};
24

25
use std::os::raw::{c_int, c_void};
26
use std::ptr;
27

28
static mut G_TRANSFORM_TOLOWER_ID: c_int = 0;
29
static mut G_TRANSFORM_TOUPPER_ID: c_int = 0;
30

31
unsafe extern "C" fn tolower_setup(
721✔
32
    _de: *mut DetectEngineCtx, s: *mut Signature, _raw: *const std::os::raw::c_char,
721✔
33
) -> c_int {
721✔
34
    return SCDetectSignatureAddTransform(s, G_TRANSFORM_TOLOWER_ID, ptr::null_mut());
721✔
35
}
721✔
36

UNCOV
37
fn tolower_transform_do(input: &[u8], output: &mut [u8]) {
×
UNCOV
38
    for (i, o) in input.iter().zip(output.iter_mut()) {
×
UNCOV
39
        *o = (*i).to_ascii_lowercase();
×
UNCOV
40
    }
×
UNCOV
41
}
×
42

UNCOV
43
unsafe extern "C" fn tolower_transform(
×
UNCOV
44
    _det: *mut DetectEngineThreadCtx, buffer: *mut InspectionBuffer, _ctx: *mut c_void,
×
UNCOV
45
) {
×
UNCOV
46
    let input = (*buffer).inspect;
×
UNCOV
47
    let input_len = (*buffer).inspect_len;
×
UNCOV
48
    if input.is_null() || input_len == 0 {
×
49
        return;
×
UNCOV
50
    }
×
UNCOV
51
    let input = build_slice!(input, input_len as usize);
×
UNCOV
52

×
UNCOV
53
    let output = SCInspectionBufferCheckAndExpand(buffer, input_len);
×
UNCOV
54
    if output.is_null() {
×
55
        // allocation failure
56
        return;
×
UNCOV
57
    }
×
UNCOV
58
    let output = std::slice::from_raw_parts_mut(output, input_len as usize);
×
UNCOV
59

×
UNCOV
60
    tolower_transform_do(input, output);
×
UNCOV
61

×
UNCOV
62
    SCInspectionBufferTruncate(buffer, input_len);
×
UNCOV
63
}
×
64

65
unsafe extern "C" fn tolower_validate(content: *const u8, len: u16, _ctx: *mut c_void) -> bool {
356✔
66
    let input = build_slice!(content, len as usize);
356✔
67
    for &c in input {
2,001✔
68
        if c.is_ascii_uppercase() {
1,655✔
69
            return false;
10✔
70
        }
1,645✔
71
    }
72
    return true;
346✔
73
}
356✔
74

75
#[no_mangle]
76
pub unsafe extern "C" fn DetectTransformToLowerRegister() {
3✔
77
    let kw = SCTransformTableElmt {
3✔
78
        name: b"to_lowercase\0".as_ptr() as *const libc::c_char,
3✔
79
        desc: b"convert buffer to lowercase\0".as_ptr() as *const libc::c_char,
3✔
80
        url: b"/rules/transforms.html#to_lowercase\0".as_ptr() as *const libc::c_char,
3✔
81
        Setup: Some(tolower_setup),
3✔
82
        flags: SIGMATCH_NOOPT,
3✔
83
        Transform: Some(tolower_transform),
3✔
84
        Free: None,
3✔
85
        TransformValidate: Some(tolower_validate),
3✔
86
        TransformId: None,
3✔
87
    };
3✔
88
    G_TRANSFORM_TOLOWER_ID = SCDetectHelperTransformRegister(&kw);
3✔
89
    if G_TRANSFORM_TOLOWER_ID < 0 {
3✔
90
        SCLogWarning!("Failed registering transform tolower");
×
91
    }
3✔
92
}
3✔
93

94
unsafe extern "C" fn toupper_setup(
209✔
95
    _de: *mut DetectEngineCtx, s: *mut Signature, _raw: *const std::os::raw::c_char,
209✔
96
) -> c_int {
209✔
97
    return SCDetectSignatureAddTransform(s, G_TRANSFORM_TOUPPER_ID, ptr::null_mut());
209✔
98
}
209✔
99

UNCOV
100
fn toupper_transform_do(input: &[u8], output: &mut [u8]) {
×
UNCOV
101
    for (i, o) in input.iter().zip(output.iter_mut()) {
×
UNCOV
102
        *o = (*i).to_ascii_uppercase();
×
UNCOV
103
    }
×
UNCOV
104
}
×
105

UNCOV
106
unsafe extern "C" fn toupper_transform(
×
UNCOV
107
    _det: *mut DetectEngineThreadCtx, buffer: *mut InspectionBuffer, _ctx: *mut c_void,
×
UNCOV
108
) {
×
UNCOV
109
    let input = (*buffer).inspect;
×
UNCOV
110
    let input_len = (*buffer).inspect_len;
×
UNCOV
111
    if input.is_null() || input_len == 0 {
×
112
        return;
×
UNCOV
113
    }
×
UNCOV
114
    let input = build_slice!(input, input_len as usize);
×
UNCOV
115

×
UNCOV
116
    let output = SCInspectionBufferCheckAndExpand(buffer, input_len);
×
UNCOV
117
    if output.is_null() {
×
118
        // allocation failure
119
        return;
×
UNCOV
120
    }
×
UNCOV
121
    let output = std::slice::from_raw_parts_mut(output, input_len as usize);
×
UNCOV
122

×
UNCOV
123
    toupper_transform_do(input, output);
×
UNCOV
124

×
UNCOV
125
    SCInspectionBufferTruncate(buffer, input_len);
×
UNCOV
126
}
×
127

128
unsafe extern "C" fn toupper_validate(content: *const u8, len: u16, _ctx: *mut c_void) -> bool {
217✔
129
    let input = build_slice!(content, len as usize);
217✔
130
    for &c in input {
1,360✔
131
        if c.is_ascii_lowercase() {
1,151✔
132
            return false;
8✔
133
        }
1,143✔
134
    }
135
    return true;
209✔
136
}
217✔
137

138
#[no_mangle]
139
pub unsafe extern "C" fn DetectTransformToUpperRegister() {
3✔
140
    let kw = SCTransformTableElmt {
3✔
141
        name: b"to_uppercase\0".as_ptr() as *const libc::c_char,
3✔
142
        desc: b"convert buffer to uppercase\0".as_ptr() as *const libc::c_char,
3✔
143
        url: b"/rules/transforms.html#to_uppercase\0".as_ptr() as *const libc::c_char,
3✔
144
        Setup: Some(toupper_setup),
3✔
145
        flags: SIGMATCH_NOOPT,
3✔
146
        Transform: Some(toupper_transform),
3✔
147
        Free: None,
3✔
148
        TransformValidate: Some(toupper_validate),
3✔
149
        TransformId: None,
3✔
150
    };
3✔
151
    G_TRANSFORM_TOUPPER_ID = SCDetectHelperTransformRegister(&kw);
3✔
152
    if G_TRANSFORM_TOUPPER_ID < 0 {
3✔
153
        SCLogWarning!("Failed registering transform toupper");
×
154
    }
3✔
155
}
3✔
156

157
#[cfg(test)]
158
mod tests {
159
    use super::*;
160

161
    #[test]
162
    fn test_tolower_transform() {
163
        let buf = b" A b C D ";
164
        let mut out = vec![0; buf.len()];
165
        tolower_transform_do(buf, &mut out);
166
        assert_eq!(out, b" a b c d ");
167
    }
168

169
    #[test]
170
    fn test_toupper_transform() {
171
        let buf = b" A b C D ";
172
        let mut out = vec![0; buf.len()];
173
        toupper_transform_do(buf, &mut out);
174
        assert_eq!(out, b" A B C D ");
175
    }
176
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc