diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2020-12-08 11:02:54 +0000 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2020-12-08 11:07:43 +0000 |
commit | 105f4a0f393c55bdffd30ae39414251c37182522 (patch) | |
tree | 242a9ced61096a63ea66e73266d0539731666bd4 /fuzzing/fuzz_date_time_new_from_iso8601.c | |
parent | b201e028b20b7f668fc2216918ce37d606ad1330 (diff) | |
download | glib-105f4a0f393c55bdffd30ae39414251c37182522.tar.gz |
fuzzing: Add more fuzzing tests for various string parsing functions
There’s no explicit guarantee that any of these functions are safe to
use on untrusted data, but it does no harm to test them.
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Diffstat (limited to 'fuzzing/fuzz_date_time_new_from_iso8601.c')
-rw-r--r-- | fuzzing/fuzz_date_time_new_from_iso8601.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fuzzing/fuzz_date_time_new_from_iso8601.c b/fuzzing/fuzz_date_time_new_from_iso8601.c new file mode 100644 index 000000000..be53a1319 --- /dev/null +++ b/fuzzing/fuzz_date_time_new_from_iso8601.c @@ -0,0 +1,25 @@ +#include "fuzz.h" + +int +LLVMFuzzerTestOneInput (const unsigned char *data, size_t size) +{ + unsigned char *nul_terminated_data = NULL; + GDateTime *dt = NULL; + + fuzz_set_logging_func (); + + /* ignore @size (the function doesn’t support it); ensure @data is nul-terminated */ + nul_terminated_data = (unsigned char *) g_strndup ((const gchar *) data, size); + dt = g_date_time_new_from_iso8601 ((const gchar *) nul_terminated_data, NULL); + g_free (nul_terminated_data); + + if (dt != NULL) + { + gchar *text = g_date_time_format_iso8601 (dt); + g_free (text); + } + + g_clear_pointer (&dt, g_date_time_unref); + + return 0; +} |