aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build3
-rw-r--r--meson_options.txt2
-rw-r--r--src/tests/meson.build15
-rw-r--r--src/tests/test-sms-part-3gpp-fuzzer.c39
-rw-r--r--src/tests/test-sms-part-3gpp-tr-fuzzer.c39
-rw-r--r--src/tests/test-sms-part-cdma-fuzzer.c39
6 files changed, 137 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index 12b4fa6a..b8746263 100644
--- a/meson.build
+++ b/meson.build
@@ -423,6 +423,8 @@ if enable_gtk_doc
subdir('docs/reference/libmm-glib')
endif
+enable_fuzzer = get_option('fuzzer')
+
configure_file(
output: 'config.h',
configuration: config_h,
@@ -465,4 +467,5 @@ summary({
'bash completion': enable_bash_completion,
'vala bindings': enable_vapi,
'code coverage': get_option('b_coverage'),
+ 'fuzzer': enable_fuzzer,
}, section: 'Miscellaneous')
diff --git a/meson_options.txt b/meson_options.txt
index 4181f9e5..2fb96040 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -100,3 +100,5 @@ option('man', type: 'boolean', value: true, description: 'build manual pages')
option('gtk_doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')
option('bash_completion', type: 'boolean', value: true, description: 'install bash completion files')
+
+option('fuzzer', type: 'boolean', value: false, description: 'build fuzzer tests')
diff --git a/src/tests/meson.build b/src/tests/meson.build
index ff4392d1..dc6ee3fb 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -37,3 +37,18 @@ foreach test_unit, test_deps: test_units
test(test_name, exe)
endforeach
+
+if get_option('fuzzer')
+ fuzzer_tests = ['test-sms-part-3gpp-fuzzer',
+ 'test-sms-part-3gpp-tr-fuzzer',
+ 'test-sms-part-cdma-fuzzer']
+ foreach fuzzer_test: fuzzer_tests
+ exe = executable(
+ fuzzer_test,
+ sources: fuzzer_test + '.c',
+ include_directories: top_inc,
+ dependencies: libhelpers_dep,
+ link_args : '-fsanitize=fuzzer',
+ )
+ endforeach
+endif \ No newline at end of file
diff --git a/src/tests/test-sms-part-3gpp-fuzzer.c b/src/tests/test-sms-part-3gpp-fuzzer.c
new file mode 100644
index 00000000..07e6aa47
--- /dev/null
+++ b/src/tests/test-sms-part-3gpp-fuzzer.c
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2023 Google, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdint.h>
+#include <glib.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-sms-part-3gpp.h"
+
+int
+LLVMFuzzerTestOneInput (const uint8_t *data,
+ size_t size)
+{
+ g_autoptr(MMSmsPart) part = NULL;
+ g_autoptr(GError) error = NULL;
+
+ if (!size)
+ return 0;
+
+ part = mm_sms_part_3gpp_new_from_binary_pdu (0, data, size, NULL, FALSE, &error);
+ g_assert (part || error);
+ return 0;
+}
diff --git a/src/tests/test-sms-part-3gpp-tr-fuzzer.c b/src/tests/test-sms-part-3gpp-tr-fuzzer.c
new file mode 100644
index 00000000..2f1964c5
--- /dev/null
+++ b/src/tests/test-sms-part-3gpp-tr-fuzzer.c
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2023 Google, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdint.h>
+#include <glib.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-sms-part-3gpp.h"
+
+int
+LLVMFuzzerTestOneInput (const uint8_t *data,
+ size_t size)
+{
+ g_autoptr(MMSmsPart) part = NULL;
+ g_autoptr(GError) error = NULL;
+
+ if (!size)
+ return 0;
+
+ part = mm_sms_part_3gpp_new_from_binary_pdu (0, data, size, NULL, TRUE, &error);
+ g_assert (part || error);
+ return 0;
+}
diff --git a/src/tests/test-sms-part-cdma-fuzzer.c b/src/tests/test-sms-part-cdma-fuzzer.c
new file mode 100644
index 00000000..86d48767
--- /dev/null
+++ b/src/tests/test-sms-part-cdma-fuzzer.c
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2023 Google, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdint.h>
+#include <glib.h>
+
+#define _LIBMM_INSIDE_MM
+#include <libmm-glib.h>
+
+#include "mm-sms-part-cdma.h"
+
+int
+LLVMFuzzerTestOneInput (const uint8_t *data,
+ size_t size)
+{
+ g_autoptr(MMSmsPart) part = NULL;
+ g_autoptr(GError) error = NULL;
+
+ if (!size)
+ return 0;
+
+ part = mm_sms_part_cdma_new_from_binary_pdu (0, data, size, NULL, &error);
+ g_assert (part || error);
+ return 0;
+}