networkd: make network_load_one "public" and add a fuzzer for it
This commit is contained in:
parent
e27aac11f2
commit
212bd73c78
|
@ -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;
|
||||
}
|
|
@ -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 += [
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue