• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)20 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
21 {
22     char filename[256];
23     sprintf(filename, "/tmp/libfuzzer.%d", getpid());
24 
25     FILE *fp = fopen(filename, "wb");
26     if (!fp)
27         return 0;
28     fwrite(data, size, 1, fp);
29     fclose(fp);
30 
31     OS_XML xml;
32     if (OS_ReadXML(filename, &xml) < 0) {
33         unlink(filename);
34         return 0;
35     }
36     XML_NODE node = NULL;
37     node = OS_GetElementsbyNode(&xml, NULL);
38     if (node == NULL) {
39         OS_ClearXML(&xml);
40         return 0;
41     }
42     int i = 0;
43 
44     while (node[i]) {
45         int j = 0;
46         XML_NODE cnode;
47         cnode = OS_GetElementsbyNode(&xml, node[i]);
48         if (cnode == NULL) {
49             i++;
50             continue;
51         }
52 
53         while (cnode[j]) {
54             if (cnode[j]->attributes && cnode[j]->values) {
55                 int k = 0;
56                 while (cnode[j]->attributes[k]) {
57                     k++;
58                 }
59             }
60             j++;
61         }
62 
63         OS_ClearNode(cnode);
64         i++;
65     }
66 
67     OS_ClearNode(node);
68     OS_ClearXML(&xml);
69     unlink(filename);
70     return 0;
71 }
72 
73