Coverage Report

Created: 2025-12-31 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz_xml.c
Line
Count
Source
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.34k
{
22
1.34k
    char filename[256];
23
1.34k
    sprintf(filename, "/tmp/libfuzzer.%d", getpid());
24
25
1.34k
    FILE *fp = fopen(filename, "wb");
26
1.34k
    if (!fp)
27
0
        return 0;
28
1.34k
    fwrite(data, size, 1, fp);
29
1.34k
    fclose(fp);
30
31
1.34k
    OS_XML xml;
32
1.34k
    if (OS_ReadXML(filename, &xml) < 0) {
33
1.14k
        OS_ClearXML(&xml);
34
1.14k
        unlink(filename);
35
1.14k
        return 0;
36
1.14k
    }
37
202
    XML_NODE node = NULL;
38
202
    node = OS_GetElementsbyNode(&xml, NULL);
39
202
    if (node == NULL) {
40
89
        OS_ClearXML(&xml);
41
89
        return 0;
42
89
    }
43
44
113
    int i = 0;
45
209k
    while (node[i]) {
46
209k
        int j = 0;
47
209k
        XML_NODE cnode;
48
209k
        cnode = OS_GetElementsbyNode(&xml, node[i]);
49
209k
        if (cnode == NULL) {
50
209k
            i++;
51
209k
            continue;
52
209k
        }
53
54
3.14k
        while (cnode[j]) {
55
2.70k
            if (cnode[j]->attributes && cnode[j]->values) {
56
0
                int k = 0;
57
0
                while (cnode[j]->attributes[k]) {
58
0
                    k++;
59
0
                }
60
0
            }
61
2.70k
            j++;
62
2.70k
        }
63
64
438
        OS_ClearNode(cnode);
65
438
        i++;
66
438
    }
67
68
113
    OS_ClearNode(node);
69
113
    OS_ClearXML(&xml);
70
113
    unlink(filename);
71
113
    return 0;
72
202
}
73