Merge pull request #10788 from evverx/fuzz-kmsg

tests: add a fuzzer for dev_kmsg_record
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-11-16 09:08:38 +01:00
committed by GitHub
11 changed files with 45 additions and 3 deletions
-1
View File
@@ -106,7 +106,6 @@ int cunescape_one(const char *p, size_t length, char32_t *ret, bool *eight_bit)
int r = 1;
assert(p);
assert(*p);
assert(ret);
/* Unescapes C style. Returns the unescaped character in ret.
+29
View File
@@ -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
View File
@@ -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,
+2 -2
View File
@@ -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];
@@ -235,7 +235,7 @@ static void dev_kmsg_record(Server *s, char *p, size_t l) {
j = 0;
FOREACH_DEVICE_DEVLINK(d, g) {
if (j > N_IOVEC_UDEV_FIELDS)
if (j >= N_IOVEC_UDEV_FIELDS)
break;
b = strappend("_UDEV_DEVLINK=", g);
+2
View File
@@ -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
View File
@@ -0,0 +1 @@
29,456,292891883,-;systemd[1]: Reexecuting.
+2
View File
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=c1:3
+2
View File
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=n1
@@ -0,0 +1,2 @@
12,460,1322026586,-;hey
DEVICE=+net:lo