/src/openvswitch/tests/oss-fuzz/ofp_print_target.c
Line | Count | Source |
1 | | #include <config.h> |
2 | | #include "fuzzer.h" |
3 | | #include "dp-packet.h" |
4 | | #include "openvswitch/ofp-print.h" |
5 | | #include "openvswitch/ofpbuf.h" |
6 | | #include "openvswitch/vlog.h" |
7 | | |
8 | | int |
9 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
10 | 38.8k | { |
11 | 38.8k | if (size < sizeof(struct ofp_header)) { |
12 | 4 | return 0; |
13 | 4 | } |
14 | | |
15 | 38.8k | static bool isInit = false; |
16 | 38.8k | if (!isInit) { |
17 | 1 | vlog_set_verbosity("off"); |
18 | 1 | isInit = true; |
19 | 1 | } |
20 | | |
21 | 38.8k | struct ofpbuf b; |
22 | 38.8k | ofpbuf_use_const(&b, data, size); |
23 | 3.20M | for (;;) { |
24 | | /* Check if ofpbuf contains ofp header. */ |
25 | 3.20M | struct ofp_header *oh = ofpbuf_at(&b, 0, sizeof *oh); |
26 | 3.20M | if (!oh) { |
27 | 33.4k | break; |
28 | 33.4k | } |
29 | | |
30 | | /* Check if length is geq than lower bound. */ |
31 | 3.16M | size_t length = ntohs(oh->length); |
32 | 3.16M | if (length < sizeof *oh) { |
33 | 1.16k | break; |
34 | 1.16k | } |
35 | | |
36 | | /* Check if ofpbuf contains payload. */ |
37 | 3.16M | size_t tail_len = length - sizeof *oh; |
38 | 3.16M | void *tail = ofpbuf_at(&b, sizeof *oh, tail_len); |
39 | 3.16M | if (!tail) { |
40 | 4.22k | break; |
41 | 4.22k | } |
42 | | |
43 | 3.16M | ofp_print(stdout, ofpbuf_pull(&b, length), length, NULL, NULL, 2); |
44 | 3.16M | } |
45 | 38.8k | ofpbuf_uninit(&b); |
46 | 38.8k | return 0; |
47 | 38.8k | } |