mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
fuzzing: Add fuzz tests for functions which parse paths
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
083e450d5f
commit
1140c228ab
19
fuzzing/fuzz_canonicalize_filename.c
Normal file
19
fuzzing/fuzz_canonicalize_filename.c
Normal 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() doesn’t 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
32
fuzzing/fuzz_paths.c
Normal 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;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
fuzz_targets = [
|
||||
'fuzz_bookmark',
|
||||
'fuzz_canonicalize_filename',
|
||||
'fuzz_date_parse',
|
||||
'fuzz_date_time_new_from_iso8601',
|
||||
'fuzz_dbus_message',
|
||||
@ -9,6 +10,7 @@ fuzz_targets = [
|
||||
'fuzz_key',
|
||||
'fuzz_network_address_parse',
|
||||
'fuzz_network_address_parse_uri',
|
||||
'fuzz_paths',
|
||||
'fuzz_uri_escape',
|
||||
'fuzz_uri_parse',
|
||||
'fuzz_uri_parse_params',
|
||||
|
Loading…
Reference in New Issue
Block a user