diff options
author | Evgeny Vereshchagin <evvers@ya.ru> | 2018-11-04 22:27:07 +0100 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2018-11-06 19:01:32 +0100 |
commit | 212bd73c788c464c2e19596a102feed848cb78fa (patch) | |
tree | caf3d5e19f9f3cc45ba16d88e08ff03ac951ee3d /src | |
parent | e27aac11f26e6e42d14939e9348b2723f2d532ac (diff) | |
download | systemd-212bd73c788c464c2e19596a102feed848cb78fa.tar.gz systemd-212bd73c788c464c2e19596a102feed848cb78fa.tar.bz2 systemd-212bd73c788c464c2e19596a102feed848cb78fa.zip |
networkd: make network_load_one "public" and add a fuzzer for it
Diffstat (limited to 'src')
-rw-r--r-- | src/network/fuzz-network-parser.c | 22 | ||||
-rw-r--r-- | src/network/meson.build | 8 | ||||
-rw-r--r-- | src/network/networkd-network.c | 2 | ||||
-rw-r--r-- | src/network/networkd-network.h | 1 |
4 files changed, 32 insertions, 1 deletions
diff --git a/src/network/fuzz-network-parser.c b/src/network/fuzz-network-parser.c new file mode 100644 index 0000000000..bfeb46cff3 --- /dev/null +++ b/src/network/fuzz-network-parser.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "fd-util.h" +#include "fileio.h" +#include "fs-util.h" +#include "fuzz.h" +#include "networkd-manager.h" + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + _cleanup_(manager_freep) Manager *manager = NULL; + _cleanup_fclose_ FILE *f = NULL; + _cleanup_(unlink_tempfilep) char network_config[] = "/tmp/fuzz-networkd.XXXXXX"; + + assert_se(fmkostemp_safe(network_config, "r+", &f) == 0); + if (size != 0) + assert_se(fwrite(data, size, 1, f) == 1); + + rewind(f); + assert_se(manager_new(&manager) >= 0); + (void) network_load_one(manager, network_config); + return 0; +} diff --git a/src/network/meson.build b/src/network/meson.build index db03e2234f..d4fa27a288 100644 --- a/src/network/meson.build +++ b/src/network/meson.build @@ -144,6 +144,14 @@ if conf.get('ENABLE_NETWORKD') == 1 libsystemd_network, libshared], [threads]], + + [['src/network/fuzz-network-parser.c', + 'src/fuzz/fuzz.h'], + [libnetworkd_core, + libudev_static, + libsystemd_network, + libshared], + [threads]] ] tests += [ diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index d6d59bab43..f257ac6698 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -102,7 +102,7 @@ void network_apply_anonymize_if_set(Network *network) { network->dhcp_use_timezone = false; } -static int network_load_one(Manager *manager, const char *filename) { +int network_load_one(Manager *manager, const char *filename) { _cleanup_(network_freep) Network *network = NULL; _cleanup_fclose_ FILE *file = NULL; char *d; diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 495fac83d3..919a2c4b3c 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -272,6 +272,7 @@ void network_free(Network *network); DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free); int network_load(Manager *manager); +int network_load_one(Manager *manager, const char *filename); int network_get_by_name(Manager *manager, const char *name, Network **ret); int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret); |