2020-09-24 07:53:51 +08:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Copyright(c) 2020, Google Inc. All rights reserved
|
|
|
|
//
|
|
|
|
// Author: Curtis Malainey <cujomalainey@chromium.org>
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdlib.h>
|
2021-04-13 00:14:14 +08:00
|
|
|
#include <sof/ipc/driver.h>
|
2020-09-24 07:53:51 +08:00
|
|
|
#include <sof/math/numbers.h>
|
|
|
|
#include <sof/audio/component_ext.h>
|
|
|
|
#include <sof/lib/notifier.h>
|
|
|
|
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
|
|
|
int LLVMFuzzerInitialize(int *argc, char ***argv);
|
|
|
|
// fuzz_ipc.c
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
|
|
|
|
{
|
|
|
|
// since we can always assume the mailbox is allocated
|
|
|
|
// copy the buffer to pre allocated buffer
|
2020-10-28 08:19:22 +08:00
|
|
|
struct sof_ipc_cmd_hdr *hdr = calloc(SOF_IPC_MSG_MAX_SIZE, 1);
|
2020-09-24 07:53:51 +08:00
|
|
|
|
|
|
|
memcpy_s(hdr, SOF_IPC_MSG_MAX_SIZE, Data, MIN(Size, SOF_IPC_MSG_MAX_SIZE));
|
|
|
|
|
|
|
|
// sanity check performed typically by platform dependent code
|
|
|
|
if (hdr->size < sizeof(*hdr) || hdr->size > SOF_IPC_MSG_MAX_SIZE)
|
|
|
|
goto done;
|
|
|
|
|
2021-04-30 00:50:32 +08:00
|
|
|
ipc_cmd((ipc_cmd_hdr *)hdr);
|
2020-09-24 07:53:51 +08:00
|
|
|
done:
|
|
|
|
free(hdr);
|
|
|
|
return 0; // Non-zero return values are reserved for future use.
|
|
|
|
}
|
|
|
|
|
|
|
|
int LLVMFuzzerInitialize(int *argc, char ***argv)
|
|
|
|
{
|
2020-10-15 06:01:48 +08:00
|
|
|
init_system_notify(sof_get());
|
|
|
|
|
2020-10-16 07:23:13 +08:00
|
|
|
trace_init(sof_get());
|
|
|
|
|
2020-10-15 06:01:48 +08:00
|
|
|
platform_init(sof_get());
|
|
|
|
|
2020-09-24 07:53:51 +08:00
|
|
|
/* init components */
|
|
|
|
sys_comp_init(sof_get());
|
|
|
|
|
2020-10-15 06:01:48 +08:00
|
|
|
/* init self-registered modules */
|
|
|
|
/* sys_module_init(); */
|
|
|
|
|
2020-09-24 07:53:51 +08:00
|
|
|
/* other necessary initializations, todo: follow better SOF init */
|
|
|
|
pipeline_posn_init(sof_get());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|