libfuzzer library integration tests (#681)

This commit is contained in:
bmc-msft
2021-03-17 16:18:10 -04:00
committed by GitHub
parent 4b07fdc455
commit f41f110af8
15 changed files with 401 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include <assert.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int (*fuzz_func)(const uint8_t *data, size_t size);
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
printf("initialize\n");
void *handle;
int (*b)(void);
char *error;
handle = dlopen("libbad.so", RTLD_LAZY);
if (!handle)
{
printf("can't open %s", dlerror());
return 1;
}
fuzz_func = (int (*)(const uint8_t *data, size_t size))dlsym(handle, "func");
error = dlerror();
if (error != NULL)
{
printf("%s\n", error);
exit(EXIT_FAILURE);
}
return 0;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
assert(fuzz_func != NULL);
return fuzz_func(data, size);
}