aboutsummaryrefslogtreecommitdiff
path: root/testprogs/fuzz/fuzz_rserver.c
blob: c79a37362edbe15560cadd518ee2e89798049ad6 (plain) (blame)
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
55
56
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>

#include <pcap/pcap.h>

FILE * outfile = NULL;

void fuzz_openFile(const char * name) {
    if (outfile != NULL) {
        fclose(outfile);
    }
    outfile = fopen(name, "w");
}

typedef enum {
    LOGPRIO_DEBUG,
    LOGPRIO_INFO,
    LOGPRIO_WARNING,
    LOGPRIO_ERROR
} log_priority;

void rpcapd_log(log_priority priority, const char *message, ...)
{
    va_list ap;

    va_start(ap, message);
    fprintf(outfile, "rpcapd[%d]:", priority);
    vfprintf(outfile, message, ap);
    putc('\n', outfile);
    va_end(ap);
}

void sock_initfuzz(const uint8_t *Data, size_t Size);
int daemon_serviceloop(int sockctrl, int isactive, char *passiveClients, int nullAuthAllowed, int uses_ssl);

int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    int sock;

    //initialization
    if (outfile == NULL) {
        fuzz_openFile("/dev/null");
    }

    sock_initfuzz(Data, Size);
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == INVALID_SOCKET) {
        abort();
    }
    //dummy socket, active, null auth allowed, no ssl
    daemon_serviceloop(sock, 1, malloc(0), 1, 0);

    return 0;
}