Skip to content

Commit

Permalink
fuzzing: Add uri_parser fuzzer setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Teufelchen1 committed Dec 15, 2022
1 parent 5c51686 commit 61cf1cb
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 7 deletions.
5 changes: 5 additions & 0 deletions fuzzing/uri_parser/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../Makefile.fuzzing_common

USEMODULE += uri_parser

include $(RIOTBASE)/Makefile.include
1 change: 1 addition & 0 deletions fuzzing/uri_parser/input/input0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coap:///R@[2008::1]:5own//R@[2008::1]:5own/?v=1
1 change: 1 addition & 0 deletions fuzzing/uri_parser/input/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coap://user@[2001:db8::1]:12345
1 change: 1 addition & 0 deletions fuzzing/uri_parser/input/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ftp://riot-os.org:99/bar/foo
1 change: 1 addition & 0 deletions fuzzing/uri_parser/input/input3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://riot-os.org:99/bar/foo
1 change: 1 addition & 0 deletions fuzzing/uri_parser/input/input4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coap://user@[2001:db8::1%eth0]:12345
30 changes: 30 additions & 0 deletions fuzzing/uri_parser/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 Bennet Blischke <bennet.blischke@haw-hamburg.de>
*
* 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 <err.h>
#include <unistd.h>

#include "uri_parser.h"
#include "fuzzing.h"

int main(void)
{
size_t input_len;
char *input_buf = (char *)fuzzing_read_bytes(STDIN_FILENO, &input_len);

if (input_buf == NULL) {
errx(EXIT_FAILURE, "fuzzing_read_bytes failed");
}

uri_parser_result_t uri_res;

uri_parser_process(&uri_res, input_buf, input_len);

exit(EXIT_SUCCESS);
return 0;
}
4 changes: 4 additions & 0 deletions sys/fuzzing/fuzzing.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
extern int fuzzing_netdev(gnrc_netif_t *);
extern void fuzzing_netdev_wait(void);

/* buffer sizes for reading from an fd */
#define FUZZING_BSIZE 1024
#define FUZZING_BSTEP 128

/* used by gnrc_pktbuf_malloc to exit on free */
gnrc_pktsnip_t *gnrc_pktbuf_fuzzptr = NULL;

Expand Down
8 changes: 1 addition & 7 deletions sys/include/fuzzing.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@
extern "C" {
#endif


#include <stdint.h>

#include "net/ipv6/addr.h"
#include "net/gnrc/pkt.h"


/* buffer sizes for reading from an fd */
#define FUZZING_BSIZE 1024
#define FUZZING_BSTEP 128

/**
* @brief Initialize dummy network interface with given address.
*
Expand All @@ -63,7 +57,7 @@ int fuzzing_read_packet(int fd, gnrc_pktsnip_t *pkt);
*
* @param fd File descriptor to read data from.
* @param size Byte count of the data read.
*
*
* @return pointer to the data on success, NULL otherwise.
*/
uint8_t *fuzzing_read_bytes(int fd, size_t *size);
Expand Down

0 comments on commit 61cf1cb

Please sign in to comment.