mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 01:36:17 +01:00
fuzzing: Add fuzz tests for GUri parsing and escaping
Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #110
This commit is contained in:
parent
d83d68d64c
commit
dd11160f7f
29
fuzzing/fuzz_uri_escape.c
Normal file
29
fuzzing/fuzz_uri_escape.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "fuzz.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
|
||||||
|
{
|
||||||
|
GBytes *unescaped_bytes = NULL;
|
||||||
|
gchar *escaped_string = NULL;
|
||||||
|
|
||||||
|
fuzz_set_logging_func ();
|
||||||
|
|
||||||
|
if (size > G_MAXSSIZE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unescaped_bytes = g_uri_unescape_bytes ((const gchar *) data, (gssize) size);
|
||||||
|
if (unescaped_bytes == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
escaped_string = g_uri_escape_bytes (g_bytes_get_data (unescaped_bytes, NULL),
|
||||||
|
g_bytes_get_size (unescaped_bytes),
|
||||||
|
NULL);
|
||||||
|
g_bytes_unref (unescaped_bytes);
|
||||||
|
|
||||||
|
if (escaped_string == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
g_free (escaped_string);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
26
fuzzing/fuzz_uri_parse.c
Normal file
26
fuzzing/fuzz_uri_parse.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "fuzz.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
|
||||||
|
{
|
||||||
|
GUri *uri = NULL;
|
||||||
|
gchar *uri_string = NULL;
|
||||||
|
const GUriFlags flags = G_URI_FLAGS_NONE;
|
||||||
|
|
||||||
|
fuzz_set_logging_func ();
|
||||||
|
|
||||||
|
/* ignore @size */
|
||||||
|
uri = g_uri_parse ((const gchar *) data, flags, NULL);
|
||||||
|
if (uri == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uri_string = g_uri_to_string (uri);
|
||||||
|
g_uri_unref (uri);
|
||||||
|
|
||||||
|
if (uri_string == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
g_free (uri_string);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
20
fuzzing/fuzz_uri_parse_params.c
Normal file
20
fuzzing/fuzz_uri_parse_params.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "fuzz.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
LLVMFuzzerTestOneInput (const unsigned char *data, size_t size)
|
||||||
|
{
|
||||||
|
GHashTable *parsed_params = NULL;
|
||||||
|
|
||||||
|
fuzz_set_logging_func ();
|
||||||
|
|
||||||
|
if (size > G_MAXSSIZE)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
parsed_params = g_uri_parse_params ((const gchar *) data, (gssize) size, '&', FALSE);
|
||||||
|
if (parsed_params == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
g_hash_table_unref (parsed_params);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -2,6 +2,9 @@ fuzz_targets = [
|
|||||||
'fuzz_bookmark',
|
'fuzz_bookmark',
|
||||||
'fuzz_dbus_message',
|
'fuzz_dbus_message',
|
||||||
'fuzz_key',
|
'fuzz_key',
|
||||||
|
'fuzz_uri_escape',
|
||||||
|
'fuzz_uri_parse',
|
||||||
|
'fuzz_uri_parse_params',
|
||||||
'fuzz_variant_binary',
|
'fuzz_variant_binary',
|
||||||
'fuzz_variant_text',
|
'fuzz_variant_text',
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user