1 /* Copyright 2017 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <assert.h>
7 #include <stddef.h>
8 #include <stdint.h>
9
10 extern "C" {
11 #include "cras_iodev_list.h"
12 #include "cras_mix.h"
13 #include "cras_observer.h"
14 #include "cras_rclient.h"
15 #include "cras_shm.h"
16 #include "cras_system_state.h"
17 }
18
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
20 cras_rclient* client = cras_rclient_create(0, 0, CRAS_CONTROL);
21 cras_rclient_buffer_from_client(client, data, size, NULL, 0);
22 cras_rclient_destroy(client);
23
24 return 0;
25 }
26
LLVMFuzzerInitialize(int * argc,char *** argv)27 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
28 char* shm_name;
29 if (asprintf(&shm_name, "/cras-%d", getpid()) < 0)
30 exit(-ENOMEM);
31 struct cras_server_state* exp_state =
32 (struct cras_server_state*)calloc(1, sizeof(*exp_state));
33 if (!exp_state)
34 exit(-1);
35 int rw_shm_fd = open("/dev/null", O_RDWR);
36 int ro_shm_fd = open("/dev/null", O_RDONLY);
37 cras_system_state_init("/tmp", shm_name, rw_shm_fd, ro_shm_fd, exp_state,
38 sizeof(*exp_state));
39 free(shm_name);
40
41 cras_observer_server_init();
42 cras_mix_init(0);
43 cras_iodev_list_init();
44
45 return 0;
46 }
47