1 /*
2 * Copyright (c) 2021 Todd C. Miller <Todd.Miller@sudo.ws>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <config.h>
18
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <fcntl.h>
26 #include <time.h>
27 #include <unistd.h>
28 #if defined(HAVE_STDINT_H)
29 # include <stdint.h>
30 #elif defined(HAVE_INTTYPES_H)
31 # include <inttypes.h>
32 #endif
33
34 #include "sudo_compat.h"
35 #include "sudo_conf.h"
36 #include "sudo_debug.h"
37 #include "sudo_eventlog.h"
38 #include "sudo_iolog.h"
39 #include "sudo_util.h"
40
41 #include "log_server.pb-c.h"
42 #include "logsrvd.h"
43
44 int
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
46 {
47 char tempfile[] = "/tmp/logsrvd_conf.XXXXXX";
48 size_t nwritten;
49 int fd;
50
51 /* logsrvd_conf_read() uses a conf file path, not an open file. */
52 fd = mkstemp(tempfile);
53 if (fd == -1)
54 return 0;
55 nwritten = write(fd, data, size);
56 if (nwritten != size) {
57 close(fd);
58 return 0;
59 }
60 close(fd);
61
62 if (logsrvd_conf_read(tempfile)) {
63 /* public config getters */
64 logsrvd_conf_iolog_dir();
65 logsrvd_conf_iolog_file();
66 logsrvd_conf_iolog_mode();
67 logsrvd_conf_pid_file();
68 logsrvd_conf_relay_address();
69 logsrvd_conf_relay_connect_timeout();
70 logsrvd_conf_relay_tcp_keepalive();
71 logsrvd_conf_relay_timeout();
72 logsrvd_conf_server_listen_address();
73 logsrvd_conf_server_tcp_keepalive();
74 logsrvd_conf_server_timeout();
75
76 /* free config */
77 logsrvd_conf_cleanup();
78 }
79
80 unlink(tempfile);
81
82 fflush(stdout);
83
84 return 0;
85 }
86