mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
fuzzing: Add uri_parser fuzzer setup
This commit is contained in:
parent
5c51686178
commit
82f44c5b1f
5
fuzzing/uri_parser/Makefile
Normal file
5
fuzzing/uri_parser/Makefile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
include ../Makefile.fuzzing_common
|
||||||
|
|
||||||
|
USEMODULE += uri_parser
|
||||||
|
|
||||||
|
include $(RIOTBASE)/Makefile.include
|
||||||
1
fuzzing/uri_parser/input/input0.txt
Normal file
1
fuzzing/uri_parser/input/input0.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
coap:///R@[2008::1]:5own//R@[2008::1]:5own/?v=1
|
||||||
1
fuzzing/uri_parser/input/input1.txt
Normal file
1
fuzzing/uri_parser/input/input1.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
coap://user@[2001:db8::1]:12345
|
||||||
1
fuzzing/uri_parser/input/input2.txt
Normal file
1
fuzzing/uri_parser/input/input2.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
ftp://riot-os.org:99/bar/foo
|
||||||
1
fuzzing/uri_parser/input/input3.txt
Normal file
1
fuzzing/uri_parser/input/input3.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://riot-os.org:99/bar/foo
|
||||||
1
fuzzing/uri_parser/input/input4.txt
Normal file
1
fuzzing/uri_parser/input/input4.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
coap://user@[2001:db8::1%eth0]:12345
|
||||||
30
fuzzing/uri_parser/main.c
Normal file
30
fuzzing/uri_parser/main.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2022 HAW Hamburg
|
||||||
|
*
|
||||||
|
* 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 EXIT_SUCCESS;
|
||||||
|
}
|
||||||
@ -23,6 +23,10 @@
|
|||||||
extern int fuzzing_netdev(gnrc_netif_t *);
|
extern int fuzzing_netdev(gnrc_netif_t *);
|
||||||
extern void fuzzing_netdev_wait(void);
|
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 */
|
/* used by gnrc_pktbuf_malloc to exit on free */
|
||||||
gnrc_pktsnip_t *gnrc_pktbuf_fuzzptr = NULL;
|
gnrc_pktsnip_t *gnrc_pktbuf_fuzzptr = NULL;
|
||||||
|
|
||||||
@ -48,39 +52,21 @@ fuzzing_init(ipv6_addr_t *addr, unsigned pfx_len)
|
|||||||
int
|
int
|
||||||
fuzzing_read_packet(int fd, gnrc_pktsnip_t *pkt)
|
fuzzing_read_packet(int fd, gnrc_pktsnip_t *pkt)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
size_t rsiz;
|
||||||
size_t csiz, rsiz;
|
|
||||||
|
|
||||||
/* can only be called once currently */
|
/* can only be called once currently */
|
||||||
assert(gnrc_pktbuf_fuzzptr == NULL);
|
assert(gnrc_pktbuf_fuzzptr == NULL);
|
||||||
|
|
||||||
csiz = 0;
|
uint8_t *input = fuzzing_read_bytes(fd, &rsiz);
|
||||||
rsiz = FUZZING_BSIZE;
|
if (input == NULL) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
if (gnrc_pktbuf_realloc_data(pkt, rsiz)) {
|
if (gnrc_pktbuf_realloc_data(pkt, rsiz)) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((r = read(fd, &((char *)pkt->data)[csiz], rsiz)) > 0) {
|
memcpy(pkt->data, input, rsiz);
|
||||||
assert((size_t)r <= rsiz);
|
|
||||||
|
|
||||||
csiz += r;
|
|
||||||
rsiz -= r;
|
|
||||||
|
|
||||||
if (rsiz == 0) {
|
|
||||||
if (gnrc_pktbuf_realloc_data(pkt, csiz + FUZZING_BSTEP)) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
rsiz += FUZZING_BSTEP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r == -1) {
|
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* shrink packet to actual size */
|
|
||||||
if (gnrc_pktbuf_realloc_data(pkt, csiz)) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnrc_pktbuf_fuzzptr = pkt;
|
gnrc_pktbuf_fuzzptr = pkt;
|
||||||
return 0;
|
return 0;
|
||||||
@ -116,7 +102,7 @@ fuzzing_read_bytes(int fd, size_t *size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* shrink packet to actual size */
|
/* shrink buffer to actual size */
|
||||||
if ((buffer = realloc(buffer, csiz)) == NULL) {
|
if ((buffer = realloc(buffer, csiz)) == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,17 +26,11 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "net/ipv6/addr.h"
|
#include "net/ipv6/addr.h"
|
||||||
#include "net/gnrc/pkt.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.
|
* @brief Initialize dummy network interface with given address.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user