• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The Chromium 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);
21   cras_rclient_buffer_from_client(client, data, size, -1);
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 = (struct cras_server_state *)
32     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",
38                          shm_name,
39                          rw_shm_fd,
40                          ro_shm_fd,
41                          exp_state,
42                          sizeof(*exp_state));
43   free(shm_name);
44 
45   cras_observer_server_init();
46   cras_mix_init(0);
47   cras_iodev_list_init();
48 
49   return 0;
50 }
51