• 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

92.59
/src/decode-raw.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 decode
20
 *
21
 * @{
22
 */
23

24

25
/**
26
 * \file
27
 *
28
 * \author William Metcalf <william.metcalf@gmail.com>
29
 *
30
 * Decode RAW
31
 */
32

33
#include "suricata-common.h"
34
#include "decode-raw.h"
35
#include "decode.h"
36
#include "decode-events.h"
37

38
#include "util-validate.h"
39
#include "util-unittest.h"
40
#include "util-debug.h"
41

42
int DecodeRaw(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p,
43
        const uint8_t *pkt, uint32_t len)
44
{
275,614✔
45
    DEBUG_VALIDATE_BUG_ON(pkt == NULL);
275,614✔
46

47
    StatsCounterIncr(&tv->stats, dtv->counter_raw);
275,614✔
48

49
    /* If it is ipv4 or ipv6 it should at least be the size of ipv4 */
50
    if (unlikely(len < IPV4_HEADER_LEN)) {
275,614✔
51
        ENGINE_SET_INVALID_EVENT(p, IPV4_PKT_TOO_SMALL);
22,865✔
52
        return TM_ECODE_FAILED;
22,865✔
53
    }
22,865✔
54

55

56

57
    if (IP_GET_RAW_VER(pkt) == 4) {
252,749✔
58
        if (unlikely(GET_PKT_LEN(p) > USHRT_MAX)) {
195,031✔
59
            return TM_ECODE_FAILED;
19✔
60
        }
19✔
61
        SCLogDebug("IPV4 Packet");
195,012✔
62
        DecodeIPV4(tv, dtv, p, GET_PKT_DATA(p), (uint16_t)(GET_PKT_LEN(p)));
195,012✔
63
    } else if (IP_GET_RAW_VER(pkt) == 6) {
195,012✔
64
        if (unlikely(GET_PKT_LEN(p) > USHRT_MAX)) {
54,316✔
65
            return TM_ECODE_FAILED;
19✔
66
        }
19✔
67
        SCLogDebug("IPV6 Packet");
54,297✔
68
        DecodeIPV6(tv, dtv, p, GET_PKT_DATA(p), (uint16_t)(GET_PKT_LEN(p)));
54,297✔
69
    } else {
54,297✔
70
        SCLogDebug("Unknown ip version %d", IP_GET_RAW_VER(pkt));
3,402✔
71
        ENGINE_SET_EVENT(p,IPRAW_INVALID_IPV);
3,402✔
72
    }
3,402✔
73
    return TM_ECODE_OK;
252,711✔
74
}
252,749✔
75

76
#ifdef UNITTESTS
77
#include "util-unittest-helper.h"
78
#include "packet.h"
79

80
/** DecodeRawtest01
81
 *  \brief Valid Raw packet
82
 *  \retval 0 Expected test value
83
 */
84
static int DecodeRawTest01 (void)
85
{
86
    /* IPV6/TCP/no eth header */
87
    uint8_t raw_ip[] = {
88
        0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x06, 0x40,
89
        0x20, 0x01, 0x06, 0x18, 0x04, 0x00, 0x00, 0x00,
90
        0x00, 0x00, 0x00, 0x00, 0x51, 0x99, 0xcc, 0x70,
91
        0x20, 0x01, 0x06, 0x18, 0x00, 0x01, 0x80, 0x00,
92
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
93
        0x8c, 0x9b, 0x00, 0x50, 0x6a, 0xe7, 0x07, 0x36,
94
        0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0x30,
95
        0x29, 0x9c, 0x00, 0x00, 0x02, 0x04, 0x05, 0x8c,
96
        0x04, 0x02, 0x08, 0x0a, 0x00, 0xdd, 0x1a, 0x39,
97
        0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x02 };
98
    Packet *p = PacketGetFromAlloc();
99
    FAIL_IF_NULL(p);
100
    ThreadVars tv;
101
    DecodeThreadVars dtv;
102

103
    memset(&dtv, 0, sizeof(DecodeThreadVars));
104
    memset(&tv,  0, sizeof(ThreadVars));
105

106
    FAIL_IF(PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1);
107

108
    FlowInitConfig(FLOW_QUIET);
109

110
    DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p));
111
    FAIL_IF_NOT(PacketIsIPv6(p));
112

113
    PacketFree(p);
114
    FlowShutdown();
115
    PASS;
116
}
117

118
/** DecodeRawtest02
119
 *  \brief Valid Raw packet
120
 *  \retval 0 Expected test value
121
 */
122
static int DecodeRawTest02 (void)
123
{
124
    /* IPV4/TCP/no eth header */
125
    uint8_t raw_ip[] = {
126
        0x45, 0x00, 0x00, 0x30, 0x00, 0xad, 0x40, 0x00,
127
        0x7f, 0x06, 0xac, 0xc5, 0xc0, 0xa8, 0x67, 0x02,
128
        0xc0, 0xa8, 0x66, 0x02, 0x0b, 0xc7, 0x00, 0x50,
129
        0x1d, 0xb3, 0x12, 0x37, 0x00, 0x00, 0x00, 0x00,
130
        0x70, 0x02, 0x40, 0x00, 0xb8, 0xc8, 0x00, 0x00,
131
        0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02 };
132

133
    Packet *p = PacketGetFromAlloc();
134
    FAIL_IF_NULL(p);
135
    ThreadVars tv;
136
    DecodeThreadVars dtv;
137

138
    memset(&dtv, 0, sizeof(DecodeThreadVars));
139
    memset(&tv,  0, sizeof(ThreadVars));
140

141
    FAIL_IF(PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1);
142

143
    FlowInitConfig(FLOW_QUIET);
144

145
    DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p));
146
    FAIL_IF_NOT(PacketIsIPv4(p));
147

148
    PacketFree(p);
149
    FlowShutdown();
150
    PASS;
151
}
152

153
/** DecodeRawtest03
154
 *  \brief Valid Raw packet
155
 *  \retval 0 Expected test value
156
 */
157
static int DecodeRawTest03 (void)
158
{
159
    /* IPV13 */
160
    uint8_t raw_ip[] = { 0xdf, 0x00, 0x00, 0x3d, 0x49, 0x42, 0x40, 0x00, 0x40, 0x06, 0xcf, 0x8a,
161
        0x0a, 0x1f, 0x03, 0xaf, 0x0a, 0x1f, 0x0a, 0x02, 0xa5, 0xe7, 0xde, 0xad, 0x00, 0x0c, 0xe2,
162
        0x0e, 0x8b, 0xfe, 0x0c, 0xe7, 0x80, 0x18, 0x00, 0xb7, 0xaf, 0xeb, 0x00, 0x00, 0x01, 0x01,
163
        0x08, 0x0a, 0x00, 0x08, 0xab, 0x4f, 0x34, 0x40, 0x67, 0x31, 0x3b, 0x63, 0x61, 0x74, 0x20,
164
        0x6b, 0x65, 0x79, 0x3b };
165
    Packet *p = PacketGetFromAlloc();
166
    FAIL_IF_NULL(p);
167
    ThreadVars tv;
168
    DecodeThreadVars dtv;
169

170
    memset(&dtv, 0, sizeof(DecodeThreadVars));
171
    memset(&tv,  0, sizeof(ThreadVars));
172

173
    FAIL_IF(PacketCopyData(p, raw_ip, sizeof(raw_ip)) == -1);
174

175
    FlowInitConfig(FLOW_QUIET);
176

177
    DecodeRaw(&tv, &dtv, p, raw_ip, GET_PKT_LEN(p));
178
    FAIL_IF(!ENGINE_ISSET_EVENT(p, IPRAW_INVALID_IPV));
179
    PacketFree(p);
180
    FlowShutdown();
181
    PASS;
182
}
183

184
#endif /* UNITTESTS */
185

186
/**
187
 * \brief Registers Raw unit tests
188
 * \todo More Raw tests
189
 */
190
void DecodeRawRegisterTests(void)
UNCOV
191
{
×
192
#ifdef UNITTESTS
193
    UtRegisterTest("DecodeRawTest01", DecodeRawTest01);
194
    UtRegisterTest("DecodeRawTest02", DecodeRawTest02);
195
    UtRegisterTest("DecodeRawTest03", DecodeRawTest03);
196
#endif /* UNITTESTS */
UNCOV
197
}
×
198
/**
199
 * @}
200
 */
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