Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2021 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | #include <stdio.h> |
13 | | #include <stdlib.h> |
14 | | #include <stdint.h> |
15 | | |
16 | | #include "./os_xml/os_xml.h" |
17 | | #include "./os_xml/os_xml_internal.h" |
18 | | |
19 | | int |
20 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
21 | 1.33k | { |
22 | 1.33k | char filename[256]; |
23 | 1.33k | sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |
24 | | |
25 | 1.33k | FILE *fp = fopen(filename, "wb"); |
26 | 1.33k | if (!fp) |
27 | 0 | return 0; |
28 | 1.33k | fwrite(data, size, 1, fp); |
29 | 1.33k | fclose(fp); |
30 | | |
31 | 1.33k | OS_XML xml; |
32 | 1.33k | if (OS_ReadXML(filename, &xml) < 0) { |
33 | 1.13k | unlink(filename); |
34 | 1.13k | return 0; |
35 | 1.13k | } |
36 | 202 | XML_NODE node = NULL; |
37 | 202 | node = OS_GetElementsbyNode(&xml, NULL); |
38 | 202 | if (node == NULL) { |
39 | 86 | OS_ClearXML(&xml); |
40 | 86 | return 0; |
41 | 86 | } |
42 | 116 | int i = 0; |
43 | | |
44 | 56.5k | while (node[i]) { |
45 | 56.4k | int j = 0; |
46 | 56.4k | XML_NODE cnode; |
47 | 56.4k | cnode = OS_GetElementsbyNode(&xml, node[i]); |
48 | 56.4k | if (cnode == NULL) { |
49 | 56.0k | i++; |
50 | 56.0k | continue; |
51 | 56.0k | } |
52 | | |
53 | 1.14k | while (cnode[j]) { |
54 | 740 | if (cnode[j]->attributes && cnode[j]->values) { |
55 | 179 | int k = 0; |
56 | 555 | while (cnode[j]->attributes[k]) { |
57 | 376 | k++; |
58 | 376 | } |
59 | 179 | } |
60 | 740 | j++; |
61 | 740 | } |
62 | | |
63 | 407 | OS_ClearNode(cnode); |
64 | 407 | i++; |
65 | 407 | } |
66 | | |
67 | 116 | OS_ClearNode(node); |
68 | 116 | OS_ClearXML(&xml); |
69 | 116 | unlink(filename); |
70 | 116 | return 0; |
71 | 202 | } |
72 | | |