Coverage Report

Created: 2026-05-16 07:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/util-mpm-ac-ks-small.c
Line
Count
Source
1
/* Copyright (C) 2013-2014 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
/**
19
 * \file
20
 *
21
 * \author Ken Steele <suricata@tilera.com>
22
23
 * Included by util-mpm-ac-ks.c with different SLOAD, SINDEX and
24
 * FUNC_NAME
25
 *
26
 */
27
28
/* Only included into util-mpm-ac-ks.c, which defines FUNC_NAME
29
 *
30
 */
31
#ifdef FUNC_NAME
32
33
/* This function handles (ctx->state_count < 32767) */
34
uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx,
35
                   PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen)
36
0
{
37
0
    uint32_t i = 0;
38
0
    int matches = 0;
39
40
0
    uint8_t mpm_bitarray[ctx->mpm_bitarray_size];
41
0
    memset(mpm_bitarray, 0, ctx->mpm_bitarray_size);
42
43
0
    const uint8_t* restrict xlate = ctx->translate_table;
44
0
    STYPE *state_table = (STYPE*)ctx->state_table;
45
0
    STYPE state = 0;
46
0
    int c = xlate[buf[0]];
47
    /* If buflen at least 4 bytes and buf 4-byte aligned. */
48
0
    if (buflen >= (4 + EXTRA) && ((uintptr_t)buf & 0x3) == 0) {
49
0
        BUF_TYPE data = *(BUF_TYPE* restrict)(&buf[0]);
50
0
        uint64_t index = 0;
51
        /* Process 4*floor(buflen/4) bytes. */
52
0
        i = 0;
53
0
        while ((i + EXTRA) < (buflen & ~0x3)) {
54
0
            BUF_TYPE data1 = *(BUF_TYPE* restrict)(&buf[i + 4]);
55
0
            index = SINDEX(index, state);
56
0
            state = SLOAD(state_table + index + c);
57
0
            c = xlate[BYTE1(data)];
58
0
            if (unlikely(SCHECK(state))) {
59
0
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
60
0
            }
61
0
            i++;
62
0
            index = SINDEX(index, state);
63
0
            state = SLOAD(state_table + index + c);
64
0
            c = xlate[BYTE2(data)];
65
0
            if (unlikely(SCHECK(state))) {
66
0
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
67
0
            }
68
0
            i++;
69
0
            index = SINDEX(index, state);
70
0
            state = SLOAD(state_table + index + c);
71
0
            c = xlate[BYTE3(data)];
72
0
            if (unlikely(SCHECK(state))) {
73
0
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
74
0
            }
75
0
            data = data1;
76
0
            i++;
77
0
            index = SINDEX(index, state);
78
0
            state = SLOAD(state_table + index + c);
79
0
            c = xlate[BYTE0(data)];
80
0
            if (unlikely(SCHECK(state))) {
81
0
                matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
82
0
            }
83
0
            i++;
84
0
        }
85
0
    }
86
    /* Process buflen % 4 bytes. */
87
0
    for (; i < buflen; i++) {
88
0
        size_t index = 0 ;
89
0
        index = SINDEX(index, state);
90
0
        state = SLOAD(state_table + index + c);
91
0
        if (likely(i+1 < buflen))
92
0
            c = xlate[buf[i+1]];
93
0
        if (unlikely(SCHECK(state))) {
94
0
            matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray);
95
0
        }
96
0
    } /* for (i = 0; i < buflen; i++) */
97
98
0
    return matches;
99
0
}
Unexecuted instantiation: SCACTileSearchSmall256
Unexecuted instantiation: SCACTileSearchSmall128
Unexecuted instantiation: SCACTileSearchSmall64
Unexecuted instantiation: SCACTileSearchSmall32
Unexecuted instantiation: SCACTileSearchSmall16
Unexecuted instantiation: SCACTileSearchSmall8
Unexecuted instantiation: SCACTileSearchTiny256
Unexecuted instantiation: SCACTileSearchTiny128
Unexecuted instantiation: SCACTileSearchTiny64
Unexecuted instantiation: SCACTileSearchTiny32
Unexecuted instantiation: SCACTileSearchTiny16
Unexecuted instantiation: SCACTileSearchTiny8
100
101
#endif /* FUNC_NAME */