Coverage Report

Created: 2026-02-14 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/detect-http-header-common.c
Line
Count
Source
1
/* Copyright (C) 2007-2021 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
 * \ingroup httplayer
20
 *
21
 * @{
22
 */
23
24
#include "suricata-common.h"
25
#include "threads.h"
26
#include "decode.h"
27
28
#include "detect.h"
29
#include "detect-parse.h"
30
#include "detect-engine.h"
31
#include "detect-engine-mpm.h"
32
#include "detect-engine-state.h"
33
#include "detect-engine-prefilter.h"
34
#include "detect-engine-content-inspection.h"
35
#include "detect-content.h"
36
#include "detect-pcre.h"
37
38
#include "flow.h"
39
#include "flow-var.h"
40
#include "flow-util.h"
41
42
#include "util-debug.h"
43
#include "util-unittest.h"
44
#include "util-unittest-helper.h"
45
#include "util-spm.h"
46
#include "util-print.h"
47
48
#include "app-layer.h"
49
#include "app-layer-parser.h"
50
51
#include "app-layer-htp.h"
52
#include "detect-http-header.h"
53
#include "stream-tcp.h"
54
55
#include "detect-http-header-common.h"
56
57
void *HttpHeaderThreadDataInit(void *data)
58
421k
{
59
421k
    HttpHeaderThreadData *td = SCCalloc(1, sizeof(*td));
60
421k
    if (td != NULL) {
61
421k
        if (data == NULL) {
62
0
            td->size_step = 512;
63
421k
        } else {
64
421k
            HttpHeaderThreadDataConfig *c = data;
65
421k
            td->size_step = c->size_step;
66
421k
        }
67
68
        /* initialize minimal buffers */
69
421k
        (void)HttpHeaderExpandBuffer(td, &td->buffer, 1);
70
421k
    }
71
421k
    return td;
72
421k
}
73
74
void HttpHeaderThreadDataFree(void *data)
75
421k
{
76
421k
    HttpHeaderThreadData *hdrnames = data;
77
421k
    SCFree(hdrnames->buffer.buffer);
78
421k
    SCFree(hdrnames);
79
421k
}
80
81
int HttpHeaderExpandBuffer(HttpHeaderThreadData *td,
82
        HttpHeaderBuffer *buf, uint32_t size)
83
422k
{
84
422k
    size_t extra = td->size_step;
85
422k
    while ((buf->size + extra) < (size + buf->len)) {
86
668
        extra += td->size_step;
87
668
    }
88
422k
    SCLogDebug("adding %"PRIuMAX" to the buffer", (uintmax_t)extra);
89
90
422k
    uint8_t *new_buffer = SCRealloc(buf->buffer, buf->size + extra);
91
422k
    if (unlikely(new_buffer == NULL)) {
92
0
        buf->len = 0;
93
0
        return -1;
94
0
    }
95
422k
    buf->buffer = new_buffer;
96
422k
    buf->size += extra;
97
422k
    return 0;
98
422k
}
99
100
HttpHeaderBuffer *HttpHeaderGetBufferSpace(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags,
101
        const int keyword_id, HttpHeaderThreadData **ret_hdr_td)
102
38.4k
{
103
38.4k
    *ret_hdr_td = NULL;
104
105
38.4k
    HttpHeaderThreadData *hdr_td =
106
38.4k
        DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, keyword_id);
107
38.4k
    if (hdr_td == NULL)
108
0
        return NULL;
109
38.4k
    *ret_hdr_td = hdr_td;
110
111
38.4k
    HttpHeaderBuffer *buf = &hdr_td->buffer;
112
38.4k
    buf->len = 0;
113
38.4k
    return buf;
114
38.4k
}