1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

Merge pull request #10564 from evverx/lldp-fuzzer

tests: add an lldp fuzzer
This commit is contained in:
Yu Watanabe 2018-10-30 07:54:20 +09:00 committed by GitHub
commit b9e7ea4841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 1 deletions

40
src/fuzz/fuzz-lldp.c Normal file
View File

@ -0,0 +1,40 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
#include <unistd.h>
#include "sd-event.h"
#include "sd-lldp.h"
#include "fd-util.h"
#include "fuzz.h"
#include "lldp-network.h"
static int test_fd[2] = { -1, -1 };
int lldp_network_bind_raw_socket(int ifindex) {
if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, test_fd) < 0)
return -errno;
return test_fd[0];
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
_cleanup_(sd_lldp_unrefp) sd_lldp *lldp = NULL;
assert_se(sd_event_new(&e) == 0);
assert_se(sd_lldp_new(&lldp) >= 0);
assert_se(sd_lldp_set_ifindex(lldp, 42) >= 0);
assert_se(sd_lldp_attach_event(lldp, e, 0) >= 0);
assert_se(sd_lldp_start(lldp) >= 0);
assert_se(write(test_fd[1], data, size) == (ssize_t) size);
assert_se(sd_event_run(e, 0) >= 0);
assert_se(sd_lldp_stop(lldp) >= 0);
assert_se(sd_lldp_detach_event(lldp) >= 0);
test_fd[1] = safe_close(test_fd[1]);
return 0;
}

View File

@ -27,6 +27,11 @@ fuzzers += [
libshared],
[]],
[['src/fuzz/fuzz-lldp.c'],
[libshared,
libsystemd_network],
[]],
[['src/fuzz/fuzz-ndisc-rs.c',
'src/libsystemd-network/dhcp-identifier.h',
'src/libsystemd-network/dhcp-identifier.c',

View File

@ -3589,7 +3589,6 @@ int journal_file_open_reliably(
JournalFile *template,
JournalFile **ret) {
_cleanup_free_ char *p = NULL;
int r;
r = journal_file_open(-1, fname, flags, mode, compress, compress_threshold_bytes, seal, metrics, mmap_cache,

BIN
test/fuzz/fuzz-lldp/basic Normal file

Binary file not shown.

Binary file not shown.

BIN
test/fuzz/fuzz-lldp/oui Normal file

Binary file not shown.