Coverage Report

Created: 2025-11-16 06:40

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