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

OISF / suricata / 22550902417

01 Mar 2026 07:32PM UTC coverage: 68.401% (-5.3%) from 73.687%
22550902417

Pull #14922

github

web-flow
github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: 7.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #14922: github-actions: bump actions/upload-artifact from 6.0.0 to 7.0.0

218243 of 319063 relevant lines covered (68.4%)

3284926.58 hits per line

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

86.67
/src/detect-engine-inspect-buffer.c
1
/* Copyright (C) 2025 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 Victor Julien <victor@inliniac.net>
22
 */
23

24
#include "suricata-common.h"
25
#include "detect-engine-inspect-buffer.h"
26
#include "detect.h"
27

28
#include "util-validate.h"
29

30
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
31
{
112,241,916✔
32
    /* single buffers */
33
    for (uint32_t i = 0; i < det_ctx->inspect.to_clear_idx; i++) {
112,296,699✔
34
        const uint32_t idx = det_ctx->inspect.to_clear_queue[i];
54,783✔
35
        InspectionBuffer *buffer = &det_ctx->inspect.buffers[idx];
54,783✔
36
        buffer->inspect = NULL;
54,783✔
37
        buffer->initialized = false;
54,783✔
38
    }
54,783✔
39
    det_ctx->inspect.to_clear_idx = 0;
112,241,916✔
40

41
    /* multi buffers */
42
    for (uint32_t i = 0; i < det_ctx->multi_inspect.to_clear_idx; i++) {
112,254,340✔
43
        const uint32_t idx = det_ctx->multi_inspect.to_clear_queue[i];
12,424✔
44
        InspectionBufferMultipleForList *mbuffer = &det_ctx->multi_inspect.buffers[idx];
12,424✔
45
        for (uint32_t x = 0; x <= mbuffer->max; x++) {
30,180✔
46
            InspectionBuffer *buffer = &mbuffer->inspection_buffers[x];
17,756✔
47
            buffer->inspect = NULL;
17,756✔
48
            buffer->initialized = false;
17,756✔
49
        }
17,756✔
50
        mbuffer->init = 0;
12,424✔
51
        mbuffer->max = 0;
12,424✔
52
    }
12,424✔
53
    det_ctx->multi_inspect.to_clear_idx = 0;
112,241,916✔
54
}
112,241,916✔
55

56
InspectionBuffer *InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
57
{
99,856✔
58
    return &det_ctx->inspect.buffers[list_id];
99,856✔
59
}
99,856✔
60

61
static InspectionBufferMultipleForList *InspectionBufferGetMulti(
62
        DetectEngineThreadCtx *det_ctx, const int list_id)
63
{
19,556✔
64
    InspectionBufferMultipleForList *buffer = &det_ctx->multi_inspect.buffers[list_id];
19,556✔
65
    if (!buffer->init) {
19,556✔
66
        det_ctx->multi_inspect.to_clear_queue[det_ctx->multi_inspect.to_clear_idx++] = list_id;
12,426✔
67
        buffer->init = 1;
12,426✔
68
    }
12,426✔
69
    return buffer;
19,556✔
70
}
19,556✔
71

72
/** \brief for a InspectionBufferMultipleForList get a InspectionBuffer
73
 *  \param fb the multiple buffer array
74
 *  \param local_id the index to get a buffer
75
 *  \param buffer the inspect buffer or NULL in case of error */
76
InspectionBuffer *InspectionBufferMultipleForListGet(
77
        DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
78
{
19,555✔
79
    if (unlikely(local_id >= 1024)) {
19,555✔
80
        DetectEngineSetEvent(det_ctx, DETECT_EVENT_TOO_MANY_BUFFERS);
×
81
        return NULL;
×
82
    }
×
83

84
    InspectionBufferMultipleForList *fb = InspectionBufferGetMulti(det_ctx, list_id);
19,555✔
85

86
    if (local_id >= fb->size) {
19,555✔
87
        uint32_t old_size = fb->size;
1,590✔
88
        uint32_t new_size = local_id + 1;
1,590✔
89
        uint32_t grow_by = new_size - old_size;
1,590✔
90
        SCLogDebug("size is %u, need %u, so growing by %u", old_size, new_size, grow_by);
1,590✔
91

92
        SCLogDebug("fb->inspection_buffers %p", fb->inspection_buffers);
1,590✔
93
        void *ptr = SCRealloc(fb->inspection_buffers, (local_id + 1) * sizeof(InspectionBuffer));
1,590✔
94
        if (ptr == NULL)
1,590✔
95
            return NULL;
×
96

97
        InspectionBuffer *to_zero = (InspectionBuffer *)ptr + old_size;
1,590✔
98
        SCLogDebug("ptr %p to_zero %p", ptr, to_zero);
1,590✔
99
        memset((uint8_t *)to_zero, 0, (grow_by * sizeof(InspectionBuffer)));
1,590✔
100
        fb->inspection_buffers = ptr;
1,590✔
101
        fb->size = new_size;
1,590✔
102
    }
1,590✔
103

104
    fb->max = MAX(fb->max, local_id);
19,555✔
105
    InspectionBuffer *buffer = &fb->inspection_buffers[local_id];
19,555✔
106
    SCLogDebug("using buffer %p", buffer);
19,555✔
107
#ifdef DEBUG_VALIDATION
108
    buffer->multi = true;
109
#endif
110
    return buffer;
19,555✔
111
}
19,555✔
112

113
static inline void InspectionBufferApplyTransformsInternal(DetectEngineThreadCtx *det_ctx,
114
        InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
115
{
64,305✔
116
    if (transforms) {
64,305✔
117
        for (int i = 0; i < DETECT_TRANSFORMS_MAX; i++) {
65,188✔
118
            const int id = transforms->transforms[i].transform;
65,174✔
119
            if (id == 0)
65,174✔
120
                break;
59,660✔
121
            DEBUG_VALIDATE_BUG_ON(sigmatch_table[id].Transform == NULL);
5,514✔
122
            sigmatch_table[id].Transform(det_ctx, buffer, transforms->transforms[i].options);
5,514✔
123
            SCLogDebug("applied transform %s", sigmatch_table[id].name);
5,514✔
124
        }
5,514✔
125
    }
59,674✔
126
}
64,305✔
127

128
void InspectionBufferApplyTransforms(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer,
129
        const DetectEngineTransforms *transforms)
130
{
236✔
131
    InspectionBufferApplyTransformsInternal(det_ctx, buffer, transforms);
236✔
132
}
236✔
133

134
void InspectionBufferInit(InspectionBuffer *buffer, uint32_t initial_size)
135
{
×
136
    memset(buffer, 0, sizeof(*buffer));
×
137
    buffer->buf = SCCalloc(initial_size, sizeof(uint8_t));
×
138
    if (buffer->buf != NULL) {
×
139
        buffer->size = initial_size;
×
140
    }
×
141
}
×
142

143
/** \brief setup the buffer empty */
144
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
145
{
8,137✔
146
#ifdef DEBUG_VALIDATION
147
    DEBUG_VALIDATE_BUG_ON(buffer->initialized);
148
    DEBUG_VALIDATE_BUG_ON(!buffer->multi);
149
#endif
150
    buffer->inspect = NULL;
8,137✔
151
    buffer->inspect_len = 0;
8,137✔
152
    buffer->len = 0;
8,137✔
153
    buffer->initialized = true;
8,137✔
154
}
8,137✔
155

156
/** \brief setup the buffer with our initial data */
157
void InspectionBufferSetupMulti(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer,
158
        const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
159
{
9,637✔
160
#ifdef DEBUG_VALIDATION
161
    DEBUG_VALIDATE_BUG_ON(!buffer->multi);
162
#endif
163
    buffer->inspect = buffer->orig = data;
9,637✔
164
    buffer->inspect_len = buffer->orig_len = data_len;
9,637✔
165
    buffer->len = 0;
9,637✔
166
    buffer->initialized = true;
9,637✔
167

168
    InspectionBufferApplyTransformsInternal(det_ctx, buffer, transforms);
9,637✔
169
}
9,637✔
170

171
static inline void InspectionBufferSetupInternal(DetectEngineThreadCtx *det_ctx, const int list_id,
172
        InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
173
{
54,839✔
174
#ifdef DEBUG_VALIDATION
175
    DEBUG_VALIDATE_BUG_ON(buffer->multi);
176
    DEBUG_VALIDATE_BUG_ON(buffer != InspectionBufferGet(det_ctx, list_id));
177
#endif
178
    if (buffer->inspect == NULL) {
54,843✔
179
#ifdef UNITTESTS
413✔
180
        if (det_ctx && list_id != -1)
413✔
181
#endif
413✔
182
            det_ctx->inspect.to_clear_queue[det_ctx->inspect.to_clear_idx++] = list_id;
54,843✔
183
    }
54,843✔
184
    buffer->inspect = buffer->orig = data;
54,839✔
185
    buffer->inspect_len = buffer->orig_len = data_len;
54,839✔
186
    buffer->len = 0;
54,839✔
187
    buffer->initialized = true;
54,839✔
188
}
54,839✔
189
/** \brief setup the buffer with our initial data */
190
void InspectionBufferSetup(DetectEngineThreadCtx *det_ctx, const int list_id,
191
        InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
192
{
403✔
193
    InspectionBufferSetupInternal(det_ctx, list_id, buffer, data, data_len);
403✔
194
}
403✔
195

196
/** \brief setup the buffer with our initial data */
197
void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id,
198
        InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len,
199
        const DetectEngineTransforms *transforms)
200
{
54,436✔
201
    InspectionBufferSetupInternal(det_ctx, list_id, buffer, data, data_len);
54,436✔
202
    InspectionBufferApplyTransformsInternal(det_ctx, buffer, transforms);
54,436✔
203
}
54,436✔
204

205
void InspectionBufferFree(InspectionBuffer *buffer)
206
{
2,750,560✔
207
    if (buffer->buf != NULL) {
2,750,560✔
208
        SCFree(buffer->buf);
971✔
209
    }
971✔
210
    memset(buffer, 0, sizeof(*buffer));
2,750,560✔
211
}
2,750,560✔
212

213
/**
214
 * \brief make sure that the buffer has at least 'min_size' bytes
215
 * Expand the buffer if necessary
216
 */
217
uint8_t *SCInspectionBufferCheckAndExpand(InspectionBuffer *buffer, uint32_t min_size)
218
{
5,501✔
219
    if (likely(buffer->size >= min_size))
5,501✔
220
        return buffer->buf;
4,533✔
221

222
    uint32_t new_size = (buffer->size == 0) ? 4096 : buffer->size;
2,147,483,654✔
223
    while (new_size < min_size) {
985✔
224
        new_size *= 2;
17✔
225
    }
17✔
226

227
    void *ptr = SCRealloc(buffer->buf, new_size);
968✔
228
    if (ptr != NULL) {
970✔
229
        buffer->buf = ptr;
970✔
230
        buffer->size = new_size;
970✔
231
    } else {
2,147,483,654✔
232
        return NULL;
2,147,483,647✔
233
    }
2,147,483,647✔
234
    return buffer->buf;
970✔
235
}
968✔
236

237
void SCInspectionBufferTruncate(InspectionBuffer *buffer, uint32_t buf_len)
238
{
5,497✔
239
    DEBUG_VALIDATE_BUG_ON(buffer->buf == NULL);
5,497✔
240
    DEBUG_VALIDATE_BUG_ON(buf_len > buffer->size);
5,497✔
241
    buffer->inspect = buffer->buf;
5,497✔
242
    buffer->inspect_len = buf_len;
5,497✔
243
    buffer->initialized = true;
5,497✔
244
}
5,497✔
245

246
void InspectionBufferCopy(InspectionBuffer *buffer, uint8_t *buf, uint32_t buf_len)
247
{
×
248
    SCInspectionBufferCheckAndExpand(buffer, buf_len);
×
249

250
    if (buffer->size) {
×
251
        uint32_t copy_size = MIN(buf_len, buffer->size);
×
252
        memcpy(buffer->buf, buf, copy_size);
×
253
        buffer->inspect = buffer->buf;
×
254
        buffer->inspect_len = copy_size;
×
255
        buffer->initialized = true;
256
    }
×
257
}
×
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