This patch creates a new OSS-Fuzz fuzzer targets ovsdb_parsing, together with 
new fuzzing-corpus introduced in 
https://github.com/openvswitch/ovs-fuzzing-corpus/pull/1.

From 7cf763149d0894a77a5daee830b3bdee5b0f87b9 Mon Sep 17 00:00:00 2001
From: Arthur Chan <[email protected]><mailto:[email protected]>
Date: Fri, 12 Jun 2026 18:27:53 +0100
Subject: [PATCH] OSS-Fuzz: Add new fuzzer targets ovsdb parsing.
Signed-off-by: Arthur Chan 
<[email protected]><mailto:[email protected]>
---
tests/oss-fuzz/automake.mk | 8 +++
.../config/ovsdb_parser_target.options | 2 +
tests/oss-fuzz/ovsdb_parser_target.c | 59 +++++++++++++++++++
3 files changed, 69 insertions(+)
create mode 100644 tests/oss-fuzz/config/ovsdb_parser_target.options
create mode 100644 tests/oss-fuzz/ovsdb_parser_target.c
diff --git a/tests/oss-fuzz/automake.mk b/tests/oss-fuzz/automake.mk
index 2b116e7a5..b35aa692a 100644
--- a/tests/oss-fuzz/automake.mk
+++ b/tests/oss-fuzz/automake.mk
@@ -1,6 +1,7 @@
OSS_FUZZ_TARGETS = \
tests/oss-fuzz/flow_extract_target \
tests/oss-fuzz/json_parser_target \
+ tests/oss-fuzz/ovsdb_parser_target \
tests/oss-fuzz/ofp_print_target \
tests/oss-fuzz/odp_target \
tests/oss-fuzz/miniflow_target \
@@ -20,6 +21,12 @@ tests_oss_fuzz_json_parser_target_SOURCES = \
tests_oss_fuzz_json_parser_target_LDADD = lib/libopenvswitch.la
tests_oss_fuzz_json_parser_target_LDFLAGS = $(LIB_FUZZING_ENGINE) -lc++
+tests_oss_fuzz_ovsdb_parser_target_SOURCES = \
+ tests/oss-fuzz/ovsdb_parser_target.c \
+ tests/oss-fuzz/fuzzer.h
+tests_oss_fuzz_ovsdb_parser_target_LDADD = lib/libopenvswitch.la
+tests_oss_fuzz_ovsdb_parser_target_LDFLAGS = $(LIB_FUZZING_ENGINE) -lc++
+
tests_oss_fuzz_ofp_print_target_SOURCES = \
tests/oss-fuzz/ofp_print_target.c \
tests/oss-fuzz/fuzzer.h
@@ -47,6 +54,7 @@ tests_oss_fuzz_ofctl_parse_target_LDFLAGS = 
$(LIB_FUZZING_ENGINE) -lc++
EXTRA_DIST += \
tests/oss-fuzz/config/flow_extract_target.options \
tests/oss-fuzz/config/json_parser_target.options \
+ tests/oss-fuzz/config/ovsdb_parser_target.options \
tests/oss-fuzz/config/ofp_print_target.options \
tests/oss-fuzz/config/odp_target.options \
tests/oss-fuzz/config/miniflow_target.options \
diff --git a/tests/oss-fuzz/config/ovsdb_parser_target.options 
b/tests/oss-fuzz/config/ovsdb_parser_target.options
new file mode 100644
index 000000000..8d3739a53
--- /dev/null
+++ b/tests/oss-fuzz/config/ovsdb_parser_target.options
@@ -0,0 +1,2 @@
+[libfuzzer]
+dict = json.dict
diff --git a/tests/oss-fuzz/ovsdb_parser_target.c 
b/tests/oss-fuzz/ovsdb_parser_target.c
new file mode 100644
index 000000000..aeb5fdff3
--- /dev/null
+++ b/tests/oss-fuzz/ovsdb_parser_target.c
@@ -0,0 +1,59 @@
+#include <config.h>
+#include "fuzzer.h"
+#include "openvswitch/json.h"
+#include "ovsdb-data.h"
+#include "ovsdb-error.h"
+#include "ovsdb-types.h"
+#include <string.h>
+
+int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+ if (!size || data[size - 1]) {
+ return 0;
+ }
+
+ /* Split on the first NUL: type JSON before it, datum JSON after. */
+ const char *type_str = (const char *) data;
+ size_t type_len = strnlen(type_str, size);
+ if (type_len == size) {
+ return 0;
+ }
+ const char *datum_str = type_str + type_len + 1;
+
+ struct json *tj = json_from_string(type_str);
+ if (tj->type == JSON_STRING) {
+ json_destroy(tj);
+ return 0;
+ }
+
+ struct ovsdb_type type;
+ struct ovsdb_error *error = ovsdb_type_from_json(&type, tj);
+ json_destroy(tj);
+ if (error) {
+ ovsdb_error_destroy(error);
+ return 0;
+ }
+
+ struct json *dj = json_from_string(datum_str);
+ if (dj->type == JSON_STRING) {
+ json_destroy(dj);
+ ovsdb_type_destroy(&type);
+ return 0;
+ }
+
+ struct ovsdb_datum d;
+ error = ovsdb_datum_from_json(&d, &type, dj, NULL);
+ json_destroy(dj);
+ if (error) {
+ ovsdb_error_destroy(error);
+ ovsdb_type_destroy(&type);
+ return 0;
+ }
+
+ json_destroy(ovsdb_datum_to_json(&d, &type));
+ ovsdb_datum_destroy(&d, &type);
+ ovsdb_type_destroy(&type);
+
+ return 0;
+}
--
2.48.1


ADA Logics Ltd is registered in England. No: 11624074.
Registered office: 266 Banbury Road, Post Box 292,
OX2 7DL, Oxford, Oxfordshire , United Kingdom
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to