Skip to content

Commit

Permalink
tests: add a fuzzer for dev_kmsg_record
Browse files Browse the repository at this point in the history
  • Loading branch information
evverx committed Nov 16, 2018
1 parent a6da77b commit 8857fb9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/fuzz/fuzz-journald-kmsg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: LGPL-2.1+ */

#include "fuzz.h"
#include "journald-kmsg.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Server s = {};
_cleanup_free_ char *buffer = NULL;

if (size == 0)
return 0;

s = (Server) {
.native_fd = -1,
.stdout_fd = -1,
.dev_kmsg_fd = -1,
.audit_fd = -1,
.hostname_fd = -1,
.notify_fd = -1,
.storage = STORAGE_NONE,
};
assert_se(sd_event_default(&s.event) >= 0);
buffer = memdup(data, size);
assert_se(buffer);
dev_kmsg_record(&s, buffer, size);
server_done(&s);

return 0;
}
5 changes: 5 additions & 0 deletions src/fuzz/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ fuzzers += [
libshared],
[libmount]],

[['src/fuzz/fuzz-journald-kmsg.c'],
[libjournal_core,
libshared],
[libselinux]],

[['src/fuzz/fuzz-journald-native.c',
'src/fuzz/fuzz-journald.c'],
[libjournal_core,
Expand Down
2 changes: 1 addition & 1 deletion src/journal/journald-kmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool is_us(const char *identifier, const char *pid) {
streq(identifier, program_invocation_short_name);
}

static void dev_kmsg_record(Server *s, char *p, size_t l) {
void dev_kmsg_record(Server *s, char *p, size_t l) {

_cleanup_free_ char *message = NULL, *syslog_priority = NULL, *syslog_pid = NULL, *syslog_facility = NULL, *syslog_identifier = NULL, *source_time = NULL, *identifier = NULL, *pid = NULL;
struct iovec iovec[N_IOVEC_META_FIELDS + 7 + N_IOVEC_KERNEL_FIELDS + 2 + N_IOVEC_UDEV_FIELDS];
Expand Down
2 changes: 2 additions & 0 deletions src/journal/journald-kmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ int server_flush_dev_kmsg(Server *s);
void server_forward_kmsg(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred);

int server_open_kernel_seqnum(Server *s);

void dev_kmsg_record(Server *s, char *p, size_t l);
1 change: 1 addition & 0 deletions test/fuzz/fuzz-journald-kmsg/basic
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
29,456,292891883,-;systemd[1]: Reexecuting.
2 changes: 2 additions & 0 deletions test/fuzz/fuzz-journald-kmsg/dev-null
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=c1:3
2 changes: 2 additions & 0 deletions test/fuzz/fuzz-journald-kmsg/loopback
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=n1
2 changes: 2 additions & 0 deletions test/fuzz/fuzz-journald-kmsg/subsystem-loopback
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=+net:lo

0 comments on commit 8857fb9

Please sign in to comment.