summaryrefslogtreecommitdiff
path: root/test/spectre_read_fuzzer.c
blob: 4a0601ae7f188eaea2690fd6f62d416d59559449 (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
50
51
52
53
54
#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);

int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    FILE *f;
    SpectreDocument *document;

/* This is part of the build, it should at least compile on Windows */
#if _POSIX_C_SOURCE >= 200809L
    f = fmemopen((void*)data, size, "rb");
    if(f == NULL) return 0;
#endif

    document = spectre_document_new();
    if(document == NULL)
    {
        fclose(f);
        return 0;
    }

    spectre_document_load_from_stream(document, f);

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

    spectre_document_free(document);
    fclose(f);

    return 0;
}

#ifdef __cplusplus
}
#endif