summaryrefslogtreecommitdiff
path: root/test/spectre_read_fuzzer.c
blob: f121d93879c8295177a8bd918d9d8a7cf8e59f03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <inttypes.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "../libspectre/spectre.h"
#include "../libspectre/spectre-utils.h"
#include "../libspectre/ps.h"

int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    SpectreRenderContext *rc;
    SpectreDocument *document;
    char path[] = "/tmp/spectre_fuzz";

    int fd = creat(path, 0644);

    if(fd == -1) return 0;

    write(fd, data, size);

    close(fd);

    document = spectre_document_new();
    if(document == NULL) return 0;

    spectre_document_load(document, path);

    if(spectre_document_status(document))
    {
        spectre_document_free(document);
        return 0;
    }

    spectre_document_free(document);

    return 0;
}

#ifdef __cplusplus
}
#endif