• 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

85.84
/src/detect-http-start.c
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
/**
25
 * \file
26
 *
27
 * \author Victor Julien <victor@inliniac.net>
28
 *
29
 * Implements http_start
30
 */
31

32
#include "suricata-common.h"
33
#include "threads.h"
34
#include "decode.h"
35

36
#include "detect.h"
37
#include "detect-parse.h"
38
#include "detect-engine.h"
39
#include "detect-engine-buffer.h"
40
#include "detect-engine-mpm.h"
41
#include "detect-engine-state.h"
42
#include "detect-engine-prefilter.h"
43
#include "detect-engine-content-inspection.h"
44
#include "detect-content.h"
45
#include "detect-pcre.h"
46
#include "detect-http-header-common.h"
47
#include "detect-http-start.h"
48

49
#include "flow.h"
50
#include "flow-var.h"
51
#include "flow-util.h"
52

53
#include "util-debug.h"
54
#include "util-unittest.h"
55
#include "util-unittest-helper.h"
56
#include "util-spm.h"
57
#include "util-print.h"
58

59
#include "app-layer.h"
60
#include "app-layer-parser.h"
61

62
#include "app-layer-htp.h"
63
#include "detect-http-header.h"
64
#include "stream-tcp.h"
65

66
#define KEYWORD_NAME "http.start"
6✔
67
#define KEYWORD_NAME_LEGACY "http_start"
3✔
68
#define KEYWORD_DOC "http-keywords.html#http-start"
3✔
69
#define BUFFER_NAME "http_start"
21✔
70
#define BUFFER_DESC "http start: request/response line + headers"
3✔
71
static int g_buffer_id = 0;
72
static int g_keyword_thread_id = 0;
73

74
#define BUFFER_SIZE_STEP    2048
75
static HttpHeaderThreadDataConfig g_td_config = { BUFFER_SIZE_STEP };
76

77
static uint8_t *GetBufferForTX(
78
        htp_tx_t *tx, DetectEngineThreadCtx *det_ctx, uint8_t flags, uint32_t *buffer_len)
79
{
53✔
80
    *buffer_len = 0;
53✔
81

82
    HttpHeaderThreadData *hdr_td = NULL;
53✔
83
    HttpHeaderBuffer *buf = HttpHeaderGetBufferSpace(det_ctx, flags, g_keyword_thread_id, &hdr_td);
53✔
84
    if (unlikely(buf == NULL)) {
53✔
85
        return NULL;
×
86
    }
×
87

88
    const bstr *line = NULL;
53✔
89
    const htp_headers_t *headers;
53✔
90
    if (flags & STREAM_TOSERVER) {
53✔
91
        if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
53✔
92
                HTP_REQUEST_PROGRESS_HEADERS)
53✔
93
            return NULL;
3✔
94
        line = htp_tx_request_line(tx);
50✔
95
        headers = htp_tx_request_headers(tx);
50✔
96
    } else {
50✔
UNCOV
97
        if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
×
UNCOV
98
                HTP_RESPONSE_PROGRESS_HEADERS)
×
UNCOV
99
            return NULL;
×
UNCOV
100
        headers = htp_tx_response_headers(tx);
×
UNCOV
101
        line = htp_tx_response_line(tx);
×
UNCOV
102
    }
×
103
    if (line == NULL || headers == NULL)
50✔
104
        return NULL;
5✔
105

106
    size_t line_size = bstr_len(line) + 2;
45✔
107
    if (line_size + buf->len > buf->size) {
45✔
UNCOV
108
        if (HttpHeaderExpandBuffer(hdr_td, buf, line_size) != 0) {
×
109
            return NULL;
×
110
        }
×
UNCOV
111
    }
×
112
    memcpy(buf->buffer + buf->len, bstr_ptr(line), bstr_size(line));
45✔
113
    buf->len += bstr_size(line);
45✔
114
    buf->buffer[buf->len++] = '\r';
45✔
115
    buf->buffer[buf->len++] = '\n';
45✔
116

117
    size_t i = 0;
45✔
118
    size_t no_of_headers = htp_headers_size(headers);
45✔
119
    for (; i < no_of_headers; i++) {
394✔
120
        const htp_header_t *h = htp_headers_get_index(headers, i);
349✔
121
        size_t size1 = htp_header_name_len(h);
349✔
122
        size_t size2 = htp_header_value_len(h);
349✔
123
        size_t size = size1 + size2 + 4;
349✔
124
        if (i + 1 == no_of_headers)
349✔
125
            size += 2;
45✔
126
        if (size + buf->len > buf->size) {
349✔
127
            if (HttpHeaderExpandBuffer(hdr_td, buf, size) != 0) {
×
128
                return NULL;
×
129
            }
×
130
        }
×
131

132
        memcpy(buf->buffer + buf->len, htp_header_name_ptr(h), htp_header_name_len(h));
349✔
133
        buf->len += htp_header_name_len(h);
349✔
134
        buf->buffer[buf->len++] = ':';
349✔
135
        buf->buffer[buf->len++] = ' ';
349✔
136
        memcpy(buf->buffer + buf->len, htp_header_value_ptr(h), htp_header_value_len(h));
349✔
137
        buf->len += htp_header_value_len(h);
349✔
138
        buf->buffer[buf->len++] = '\r';
349✔
139
        buf->buffer[buf->len++] = '\n';
349✔
140
        if (i + 1 == no_of_headers) {
349✔
141
            buf->buffer[buf->len++] = '\r';
45✔
142
            buf->buffer[buf->len++] = '\n';
45✔
143
        }
45✔
144
    }
349✔
145

146
    *buffer_len = buf->len;
45✔
147
    return buf->buffer;
45✔
148
}
45✔
149

150
static InspectionBuffer *GetBuffer1ForTX(DetectEngineThreadCtx *det_ctx,
151
        const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv,
152
        const int list_id)
153
{
97✔
154
    InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
97✔
155
    if (buffer->inspect == NULL) {
97✔
156
        uint32_t rawdata_len = 0;
53✔
157
        uint8_t *rawdata = GetBufferForTX(txv, det_ctx, flow_flags, &rawdata_len);
53✔
158
        if (rawdata_len == 0)
53✔
159
            return NULL;
8✔
160

161
        InspectionBufferSetupAndApplyTransforms(
45✔
162
                det_ctx, list_id, buffer, rawdata, rawdata_len, transforms);
45✔
163
    }
45✔
164

165
    return buffer;
89✔
166
}
97✔
167

168
static int DetectHttpStartSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
169
{
138✔
170
    if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
138✔
171
        return -1;
1✔
172

173
    if (SCDetectSignatureSetAppProto(s, ALPROTO_HTTP1) < 0)
137✔
174
        return -1;
2✔
175

176
    return 0;
135✔
177
}
137✔
178

179
/**
180
 * \brief Registers the keyword handlers for the "http_start" keyword.
181
 */
182
void DetectHttpStartRegister(void)
183
{
3✔
184
    sigmatch_table[DETECT_HTTP_START].name = KEYWORD_NAME;
3✔
185
    sigmatch_table[DETECT_HTTP_START].alias = KEYWORD_NAME_LEGACY;
3✔
186
    sigmatch_table[DETECT_HTTP_START].desc = BUFFER_NAME " sticky buffer";
3✔
187
    sigmatch_table[DETECT_HTTP_START].url = "/rules/" KEYWORD_DOC;
3✔
188
    sigmatch_table[DETECT_HTTP_START].Setup = DetectHttpStartSetup;
3✔
189
    sigmatch_table[DETECT_HTTP_START].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
3✔
190

191
    DetectAppLayerMpmRegister(BUFFER_NAME, SIG_FLAG_TOSERVER, 2, PrefilterGenericMpmRegister,
3✔
192
            GetBuffer1ForTX, ALPROTO_HTTP1, HTP_REQUEST_PROGRESS_HEADERS);
3✔
193
    DetectAppLayerMpmRegister(BUFFER_NAME, SIG_FLAG_TOCLIENT, 2, PrefilterGenericMpmRegister,
3✔
194
            GetBuffer1ForTX, ALPROTO_HTTP1, HTP_RESPONSE_PROGRESS_HEADERS);
3✔
195

196
    DetectAppLayerInspectEngineRegister(BUFFER_NAME, ALPROTO_HTTP1, SIG_FLAG_TOSERVER,
3✔
197
            HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetBuffer1ForTX);
3✔
198
    DetectAppLayerInspectEngineRegister(BUFFER_NAME, ALPROTO_HTTP1, SIG_FLAG_TOCLIENT,
3✔
199
            HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetBuffer1ForTX);
3✔
200

201
    DetectBufferTypeSetDescriptionByName(BUFFER_NAME,
3✔
202
            BUFFER_DESC);
3✔
203

204
    g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);
3✔
205

206
    g_keyword_thread_id = DetectRegisterThreadCtxGlobalFuncs(KEYWORD_NAME,
3✔
207
            HttpHeaderThreadDataInit, &g_td_config, HttpHeaderThreadDataFree);
3✔
208

209
    SCLogDebug("keyword %s registered. Thread id %d. "
3✔
210
            "Buffer %s registered. Buffer id %d",
3✔
211
            KEYWORD_NAME, g_keyword_thread_id,
3✔
212
            BUFFER_NAME, g_buffer_id);
3✔
213
}
3✔
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