suricata
fuzz_applayerprotodetectgetproto.c
Go to the documentation of this file.
1/**
2 * @file
3 * @author Philippe Antoine <contact@catenacyber.fr>
4 * fuzz target for AppLayerProtoDetectGetProto
5 */
6
7
8#include "suricata-common.h"
9#include "suricata.h"
11#include "flow-util.h"
12#include "app-layer.h"
14#include "conf-yaml-loader.h"
15
16#define HEADER_LEN 6
17
18extern const char *configNoChecksum;
19
20int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
21
23SC_ATOMIC_EXTERN(unsigned int, engine_stage);
24
25int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
26{
27 Flow *f;
28 TcpSession ssn;
29 bool reverse = false;
30
31 if (alpd_tctx == NULL) {
32 //global init
33 InitGlobal();
36 abort();
37 }
43 SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);
44 }
45
46 if (size < HEADER_LEN) {
47 return 0;
48 }
49
50 f = TestHelperBuildFlow(AF_INET, "1.2.3.4", "5.6.7.8", (uint16_t)((data[2] << 8) | data[3]),
51 (uint16_t)((data[4] << 8) | data[5]));
52 if (f == NULL) {
53 return 0;
54 }
55 f->proto = data[1];
56 memset(&ssn, 0, sizeof(TcpSession));
57 f->protoctx = &ssn;
59
60 uint8_t flags = STREAM_TOCLIENT;
61 if (data[0] & STREAM_TOSERVER) {
62 flags = STREAM_TOSERVER;
63 }
64 AppLayerProtoDetectGetProto(alpd_tctx, f, data + HEADER_LEN, (uint32_t)(size - HEADER_LEN),
65 f->proto, flags, &reverse);
66 FlowFree(f);
67
68 return 0;
69}
AppProto AppLayerProtoDetectGetProto(AppLayerProtoDetectThreadCtx *tctx, Flow *f, const uint8_t *buf, uint32_t buflen, uint8_t ipproto, uint8_t flags, bool *reverse_flow)
Returns the app layer protocol given a buffer.
AppLayerProtoDetectThreadCtx * AppLayerProtoDetectGetCtxThread(void)
Inits and returns an app layer protocol detection thread context.
int AppLayerSetup(void)
Setup the app layer.
Definition app-layer.c:1078
int SCConfYamlLoadString(const char *string, size_t len)
Load configuration from a YAML string.
uint8_t flags
Definition decode-gre.h:0
uint8_t FlowGetProtoMapping(uint8_t proto)
Function to map the protocol to the defined FLOW_PROTO_* enumeration.
Definition flow-util.c:99
void FlowFree(Flow *f)
cleanup & free the memory of a flow
Definition flow-util.c:84
AppLayerProtoDetectThreadCtx * alpd_tctx
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
const char * configNoChecksum
Definition confyaml.c:1
@ RUNMODE_UNITTEST
Definition runmodes.h:41
The app layer protocol detection thread context.
Flow data structure.
Definition flow.h:356
uint8_t proto
Definition flow.h:378
void * protoctx
Definition flow.h:441
uint8_t protomap
Definition flow.h:445
int InitGlobal(void)
Global initialization common to all runmodes.
Definition suricata.c:2965
void EngineModeSetIDS(void)
Definition suricata.c:264
void SCRunmodeSet(SCRunMode run_mode)
Set the current run mode.
Definition suricata.c:284
@ SURICATA_RUNTIME
Definition suricata.h:101
#define SC_ATOMIC_EXTERN(type, name)
wrapper for referencing an atomic variable declared on another file.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
void MpmTableSetup(void)
Definition util-mpm.c:224
void SpmTableSetup(void)
Definition util-spm.c:122
Flow * TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)