Merge branch 'fuzz-path-functions' into 'master'

fuzzing: Add fuzz tests for functions which parse paths

See merge request GNOME/glib!2006
This commit is contained in:
Philip Withnall 2021-03-24 11:16:49 +00:00
commit eaaa41f98f
3 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#include "fuzz.h"
int
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
{
unsigned char *nul_terminated_data = NULL;
gchar *canonicalized = NULL;
fuzz_set_logging_func ();
/* ignore @size (g_canonicalize_filename() doesnt support it); ensure @data is nul-terminated */
nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
canonicalized = g_canonicalize_filename ((const gchar *) nul_terminated_data, "/");
g_free (nul_terminated_data);
g_free (canonicalized);
return 0;
}

32
fuzzing/fuzz_paths.c Normal file
View File

@ -0,0 +1,32 @@
#include "fuzz.h"
int
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
{
unsigned char *nul_terminated_data = NULL;
const gchar *skipped_root;
gchar *basename = NULL, *dirname = NULL;
fuzz_set_logging_func ();
/* ignore @size (none of the functions support it); ensure @data is nul-terminated */
nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size);
g_path_is_absolute ((const gchar *) nul_terminated_data);
skipped_root = g_path_skip_root ((const gchar *) nul_terminated_data);
g_assert (skipped_root == NULL || skipped_root >= (const gchar *) nul_terminated_data);
g_assert (skipped_root == NULL || skipped_root <= (const gchar *) nul_terminated_data + size);
basename = g_path_get_basename ((const gchar *) nul_terminated_data);
g_assert (strlen (basename) <= size);
dirname = g_path_get_dirname ((const gchar *) nul_terminated_data);
g_assert (strlen (dirname) <= size);
g_free (nul_terminated_data);
g_free (dirname);
g_free (basename);
return 0;
}

View File

@ -1,5 +1,6 @@
fuzz_targets = [ fuzz_targets = [
'fuzz_bookmark', 'fuzz_bookmark',
'fuzz_canonicalize_filename',
'fuzz_date_parse', 'fuzz_date_parse',
'fuzz_date_time_new_from_iso8601', 'fuzz_date_time_new_from_iso8601',
'fuzz_dbus_message', 'fuzz_dbus_message',
@ -9,6 +10,7 @@ fuzz_targets = [
'fuzz_key', 'fuzz_key',
'fuzz_network_address_parse', 'fuzz_network_address_parse',
'fuzz_network_address_parse_uri', 'fuzz_network_address_parse_uri',
'fuzz_paths',
'fuzz_uri_escape', 'fuzz_uri_escape',
'fuzz_uri_parse', 'fuzz_uri_parse',
'fuzz_uri_parse_params', 'fuzz_uri_parse_params',