From 0a713d52bbf3e061823d1a7f35e5303e7320f27a Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Tue, 11 May 2021 14:59:23 +0200 Subject: [PATCH] fuzz: use binary directory for ESPEAK_DATA_PATH instead of current working directory so, the fuzzer can be launched from anywhere --- tests/ssml-fuzzer.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/ssml-fuzzer.c b/tests/ssml-fuzzer.c index 822a8c1a..dae7bfdf 100644 --- a/tests/ssml-fuzzer.c +++ b/tests/ssml-fuzzer.c @@ -20,6 +20,8 @@ #include #include +#include +#include #include @@ -37,9 +39,19 @@ static int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) { /* See http://llvm.org/docs/LibFuzzer.html */ extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); +extern int LLVMFuzzerInitialize(const int* argc, char*** argv); + +char *filepath = NULL; + +extern int LLVMFuzzerInitialize(const int* argc, char*** argv) +{ + filepath = dirname(strdup((*argv)[0])); + return 0; +} + extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (!initialized) { - setenv("ESPEAK_DATA_PATH",".",0); + setenv("ESPEAK_DATA_PATH",filepath,0); espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, NULL, 0); espeak_SetSynthCallback(SynthCallback); initialized = 1;