add fuzzing
This commit is contained in:
parent
8d38746586
commit
5467b4180b
6 changed files with 72 additions and 1 deletions
13
meson.build
13
meson.build
|
@ -305,6 +305,8 @@ subdir('src/pacman')
|
||||||
subdir('src/util')
|
subdir('src/util')
|
||||||
subdir('scripts')
|
subdir('scripts')
|
||||||
|
|
||||||
|
subdir('src/fuzzing')
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
if get_option('i18n')
|
if get_option('i18n')
|
||||||
i18n = import('i18n')
|
i18n = import('i18n')
|
||||||
|
@ -398,6 +400,17 @@ executable(
|
||||||
install : true,
|
install : true,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Note: this target must be built with clang!
|
||||||
|
executable(
|
||||||
|
'fuzz_wordsplit',
|
||||||
|
fuzzing_sources,
|
||||||
|
include_directories : includes,
|
||||||
|
link_with : [libcommon],
|
||||||
|
dependencies : [],
|
||||||
|
c_args : ['-fsanitize=fuzzer,address', '-ggdb'],
|
||||||
|
link_args : ['-fsanitize=fuzzer,address', '-ggdb'],
|
||||||
|
)
|
||||||
|
|
||||||
foreach wrapper : script_wrappers
|
foreach wrapper : script_wrappers
|
||||||
cdata = configuration_data()
|
cdata = configuration_data()
|
||||||
cdata.set_quoted('BASH', BASH.full_path())
|
cdata.set_quoted('BASH', BASH.full_path())
|
||||||
|
|
26
src/fuzzing/fuzz_util_string_length.c
Normal file
26
src/fuzzing/fuzz_util_string_length.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#define _XOPEN_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
||||||
|
|
||||||
|
static int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
|
if (Size == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Prepare a null terminated string
|
||||||
|
char* cstring = malloc(Size+1);
|
||||||
|
memcpy(cstring, Data, Size);
|
||||||
|
cstring[Size] = 0;
|
||||||
|
|
||||||
|
string_length(cstring);
|
||||||
|
|
||||||
|
free(cstring);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
28
src/fuzzing/fuzz_wordsplit.c
Normal file
28
src/fuzzing/fuzz_wordsplit.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#define _XOPEN_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#include "util-common.h"
|
||||||
|
|
||||||
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
||||||
|
|
||||||
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
|
if (Size == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Prepare a null terminated string
|
||||||
|
char* cstring = malloc(Size+1);
|
||||||
|
memcpy(cstring, Data, Size);
|
||||||
|
cstring[Size] = 0;
|
||||||
|
|
||||||
|
char** ptr = wordsplit(cstring);
|
||||||
|
if (ptr)
|
||||||
|
free(ptr);
|
||||||
|
|
||||||
|
free(cstring);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
3
src/fuzzing/meson.build
Normal file
3
src/fuzzing/meson.build
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fuzzing_sources = files('''
|
||||||
|
fuzz_wordsplit.c
|
||||||
|
'''.split())
|
|
@ -449,7 +449,7 @@ static char *concat_list(alpm_list_t *lst, formatfn fn)
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t string_length(const char *s)
|
size_t string_length(const char *s)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
wchar_t *wcstr;
|
wchar_t *wcstr;
|
||||||
|
|
|
@ -47,6 +47,7 @@ typedef struct _pm_target_t {
|
||||||
int is_explicit;
|
int is_explicit;
|
||||||
} pm_target_t;
|
} pm_target_t;
|
||||||
|
|
||||||
|
size_t string_length(const char *s);
|
||||||
void trans_init_error(void);
|
void trans_init_error(void);
|
||||||
/* flags is a bitfield of alpm_transflag_t flags */
|
/* flags is a bitfield of alpm_transflag_t flags */
|
||||||
int trans_init(int flags, int check_valid);
|
int trans_init(int flags, int check_valid);
|
||||||
|
|
Loading…
Add table
Reference in a new issue