]> The Tcpdump Group git mirrors - libpcap/blob - testprogs/fuzz/fuzz_rserver.c
Make sure no read routine process more than INT_MAX packets.
[libpcap] / testprogs / fuzz / fuzz_rserver.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <errno.h>
5 #include <stdarg.h>
6
7 #include <pcap/pcap.h>
8
9 FILE * outfile = NULL;
10
11 void fuzz_openFile(const char * name) {
12 if (outfile != NULL) {
13 fclose(outfile);
14 }
15 outfile = fopen(name, "w");
16 }
17
18 typedef enum {
19 LOGPRIO_DEBUG,
20 LOGPRIO_INFO,
21 LOGPRIO_WARNING,
22 LOGPRIO_ERROR
23 } log_priority;
24
25 void rpcapd_log(log_priority priority, const char *message, ...)
26 {
27 va_list ap;
28
29 va_start(ap, message);
30 fprintf(outfile, "rpcapd[%d]:", priority);
31 vfprintf(outfile, message, ap);
32 putc('\n', outfile);
33 va_end(ap);
34 }
35
36 void sock_initfuzz(const uint8_t *Data, size_t Size);
37 int daemon_serviceloop(int sockctrl, int isactive, char *passiveClients, int nullAuthAllowed, int uses_ssl);
38
39 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
40 int sock;
41
42 //initialization
43 if (outfile == NULL) {
44 fuzz_openFile("/dev/null");
45 }
46
47 sock_initfuzz(Data, Size);
48 sock = socket(AF_INET, SOCK_STREAM, 0);
49 if (sock == INVALID_SOCKET) {
50 abort();
51 }
52 //dummy socket, active, null auth allowed, no ssl
53 daemon_serviceloop(sock, 1, malloc(0), 1, 0);
54
55 return 0;
56 }