Skip to content

Commit

Permalink
networkd: make network_load_one "public" and add a fuzzer for it
Browse files Browse the repository at this point in the history
  • Loading branch information
evverx committed Nov 6, 2018
1 parent e27aac1 commit 212bd73
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/network/fuzz-network-parser.c
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions src/network/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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 += [
Expand Down
2 changes: 1 addition & 1 deletion src/network/networkd-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/network/networkd-network.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 212bd73

Please sign in to comment.