/src/libyaml_parser_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "yaml.h" |
16 | | #include <assert.h> |
17 | | #include <stdlib.h> |
18 | | #include <stdio.h> |
19 | | #include <string.h> |
20 | | #include <stdint.h> |
21 | | #include <stdbool.h> |
22 | | |
23 | | #ifdef NDEBUG |
24 | | #undef NDEBUG |
25 | | #endif |
26 | | |
27 | 8.15k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
28 | 8.15k | yaml_parser_t parser; |
29 | 8.15k | yaml_event_t event; |
30 | 8.15k | bool done = false; |
31 | | |
32 | 8.15k | if(!yaml_parser_initialize(&parser)) |
33 | 0 | return 0; |
34 | | |
35 | 8.15k | yaml_parser_set_input_string(&parser, data, size); |
36 | | |
37 | 6.56M | while (!done) |
38 | 6.56M | { |
39 | 6.56M | if (!yaml_parser_parse(&parser, &event)) break; |
40 | | |
41 | 6.56M | done = (event.type == YAML_STREAM_END_EVENT); |
42 | | |
43 | 6.56M | yaml_event_delete(&event); |
44 | 6.56M | } |
45 | | |
46 | 8.15k | yaml_parser_delete(&parser); |
47 | | |
48 | 8.15k | return 0; |
49 | 8.15k | } |