ubus/tests/fuzz/test-fuzz.c
Petr Štetiar 08f17c87a0 add fuzzer and cram based unit tests
For improved QA etc.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-16 23:39:16 +01:00

40 lines
768 B
C

#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
#include <libubox/blob.h>
#include <libubox/blobmsg.h>
#include "ubusmsg.h"
#include "libubus.h"
#include "libubus-internal.h"
static void _ubus_validate_hdr(const uint8_t *data, size_t size)
{
if (size > sizeof(struct ubus_msghdr))
return;
ubus_validate_hdr((struct ubus_msghdr *) data);
}
static void _ubus_parse_msg(const uint8_t *data, size_t size)
{
struct blob_attr *attr = (struct blob_attr *) data;
if (size < sizeof(struct blob_attr *))
return;
if (blob_pad_len(attr) > UBUS_MAX_MSGLEN)
return;
ubus_parse_msg(attr);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
_ubus_validate_hdr(data, size);
_ubus_parse_msg(data, size);
return 0;
}