From e24774b7393211fe22cf7b7d41c9cce1c0b8329a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Sat, 18 Apr 2020 12:28:08 +0200 Subject: [PATCH] fuzzing/gcoap: Initialize --- fuzzing/gcoap/Makefile | 6 +++ fuzzing/gcoap/input/confirmable-get.dat | 1 + fuzzing/gcoap/input/confirmable-post.dat | 1 + fuzzing/gcoap/input/non-confirmable-get.dat | 1 + fuzzing/gcoap/main.c | 59 +++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 fuzzing/gcoap/Makefile create mode 100644 fuzzing/gcoap/input/confirmable-get.dat create mode 100644 fuzzing/gcoap/input/confirmable-post.dat create mode 100644 fuzzing/gcoap/input/non-confirmable-get.dat create mode 100644 fuzzing/gcoap/main.c diff --git a/fuzzing/gcoap/Makefile b/fuzzing/gcoap/Makefile new file mode 100644 index 0000000000..51e6a9c4ca --- /dev/null +++ b/fuzzing/gcoap/Makefile @@ -0,0 +1,6 @@ +include ../Makefile.fuzzing_common + +USEMODULE += gnrc_ipv6 +USEMODULE += gcoap + +include $(RIOTBASE)/Makefile.include diff --git a/fuzzing/gcoap/input/confirmable-get.dat b/fuzzing/gcoap/input/confirmable-get.dat new file mode 100644 index 0000000000..ede38e5814 --- /dev/null +++ b/fuzzing/gcoap/input/confirmable-get.dat @@ -0,0 +1 @@ +@¹'=fe80::8813:2ff:fec1:98ef%tap0‹.well-knowncore \ No newline at end of file diff --git a/fuzzing/gcoap/input/confirmable-post.dat b/fuzzing/gcoap/input/confirmable-post.dat new file mode 100644 index 0000000000..a024b378fc --- /dev/null +++ b/fuzzing/gcoap/input/confirmable-post.dat @@ -0,0 +1 @@ +@¹'=fe80::8813:2ff:fec1:98ef%tap0„riotvalueÿfoo diff --git a/fuzzing/gcoap/input/non-confirmable-get.dat b/fuzzing/gcoap/input/non-confirmable-get.dat new file mode 100644 index 0000000000..fb2260ceda --- /dev/null +++ b/fuzzing/gcoap/input/non-confirmable-get.dat @@ -0,0 +1 @@ +P¹'=fe80::8813:2ff:fec1:98ef%tap0„riotboard \ No newline at end of file diff --git a/fuzzing/gcoap/main.c b/fuzzing/gcoap/main.c new file mode 100644 index 0000000000..6aebc0872c --- /dev/null +++ b/fuzzing/gcoap/main.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019 Sören Tempel + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#include +#include + +#include "thread.h" +#include "fuzzing.h" +#include "kernel_types.h" + +#include "net/gcoap.h" +#include "net/gnrc/udp.h" +#include "net/gnrc/pkt.h" +#include "net/ipv6/addr.h" +#include "net/gnrc/nettype.h" +#include "net/gnrc/ipv6/hdr.h" + +static uint32_t demux = COAP_PORT; +static gnrc_nettype_t ntype = GNRC_NETTYPE_UDP; + +void initialize(void) +{ + if (fuzzing_init(NULL, 0)) { + errx(EXIT_FAILURE, "fuzzing_init failed"); + } + + gcoap_init(); +} + +int main(void) +{ + gnrc_pktsnip_t *ipkt, *upkt, *cpkt; + + initialize(); + if (!(ipkt = gnrc_ipv6_hdr_build(NULL, NULL, &ipv6_addr_loopback))) { + errx(EXIT_FAILURE, "gnrc_ipv6_hdr_build failed"); + } + if (!(upkt = gnrc_udp_hdr_build(ipkt, 2342, COAP_PORT))) { + errx(EXIT_FAILURE, "gnrc_udp_hdr_build failed"); + } + + if (!(cpkt = gnrc_pktbuf_add(upkt, NULL, 0, GNRC_NETTYPE_UNDEF))) { + errx(EXIT_FAILURE, "gnrc_pktbuf_add failed"); + } + if (fuzzing_read_packet(STDIN_FILENO, cpkt)) { + errx(EXIT_FAILURE, "fuzzing_read_packet failed"); + } + + if (!gnrc_netapi_dispatch_receive(ntype, demux, cpkt)) { + errx(EXIT_FAILURE, "couldn't find any subscriber"); + } + + return EXIT_SUCCESS; +}