2018-05-15 09:49:10 -04:00
|
|
|
#include "no_warn_host.h"
|
2018-05-14 09:03:37 -04:00
|
|
|
#include "lwip/pbuf.h"
|
|
|
|
#include "lwip/udp.h"
|
|
|
|
#include <string.h>
|
2018-05-15 09:49:10 -04:00
|
|
|
#include <stdio.h>
|
2022-02-08 11:08:04 -05:00
|
|
|
#include "dhcpserver/dhcpserver.h"
|
2018-05-14 09:03:37 -04:00
|
|
|
|
|
|
|
const ip_addr_t ip_addr_any;
|
|
|
|
ip4_addr_t server_ip;
|
|
|
|
struct netif mynetif;
|
|
|
|
|
2018-07-27 03:26:51 -04:00
|
|
|
// dhcps callback
|
2022-02-02 11:30:20 -05:00
|
|
|
void dhcp_test_dhcps_cb (void* cb_arg, u8_t client_ip[4], u8_t client_mac[6]) {}
|
2018-07-27 03:26:51 -04:00
|
|
|
|
2018-05-14 09:03:37 -04:00
|
|
|
// Dependency injected static function to pass the packet into parser
|
|
|
|
void dhcp_test_handle_dhcp(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
|
2019-07-16 05:33:30 -04:00
|
|
|
void dhcp_test_init_di(void);
|
2018-05-14 09:03:37 -04:00
|
|
|
|
2018-05-15 09:49:10 -04:00
|
|
|
//
|
|
|
|
// Test starts here
|
|
|
|
//
|
|
|
|
int main(int argc, char** argv)
|
2018-05-14 09:03:37 -04:00
|
|
|
{
|
|
|
|
uint8_t *buf;
|
|
|
|
struct pbuf *p;
|
|
|
|
FILE *file;
|
|
|
|
size_t len = 1460;
|
|
|
|
|
|
|
|
dhcp_test_init_di();
|
|
|
|
|
|
|
|
IP4_ADDR(&server_ip, 192,168,4,1);
|
2022-01-24 03:58:06 -05:00
|
|
|
dhcps_t *dhcps = dhcps_new();
|
2022-02-02 11:30:20 -05:00
|
|
|
dhcps_set_new_lease_cb(dhcps, dhcp_test_dhcps_cb, NULL);
|
2022-01-24 03:58:06 -05:00
|
|
|
dhcps_start(dhcps, &mynetif, server_ip);
|
2018-05-14 09:03:37 -04:00
|
|
|
|
2018-05-15 09:49:10 -04:00
|
|
|
#ifdef INSTR_IS_OFF
|
|
|
|
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
|
|
|
buf = p->payload;
|
2018-05-14 09:03:37 -04:00
|
|
|
memset(buf, 0, 1460);
|
2018-05-15 09:49:10 -04:00
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
printf("Non-instrumentation mode: please supply a file name created by AFL to reproduce crash\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Note: parameter1 is a file (mangled packet) which caused the crash
|
|
|
|
file = fopen(argv[1], "r");
|
2018-05-14 09:03:37 -04:00
|
|
|
if (file) {
|
|
|
|
len = fread(buf, 1, 1460, file);
|
|
|
|
}
|
|
|
|
fclose(file);
|
2018-05-15 09:49:10 -04:00
|
|
|
|
2018-05-14 09:03:37 -04:00
|
|
|
int i;
|
|
|
|
for (i=0; i<1; i++) {
|
|
|
|
#else
|
|
|
|
while (__AFL_LOOP(1000)) {
|
2018-05-15 09:49:10 -04:00
|
|
|
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
|
|
|
buf = p->payload;
|
2018-05-14 09:03:37 -04:00
|
|
|
memset(buf, 0, 1460);
|
|
|
|
size_t len = read(0, buf, 1460);
|
|
|
|
#endif
|
|
|
|
p->len = len;
|
|
|
|
p->tot_len = len;
|
|
|
|
p->next = NULL;
|
|
|
|
|
2022-01-24 03:58:06 -05:00
|
|
|
dhcp_test_handle_dhcp(dhcps, NULL, p, &ip_addr_any, 0);
|
2018-05-14 09:03:37 -04:00
|
|
|
}
|
2022-01-24 03:58:06 -05:00
|
|
|
dhcps_stop(dhcps, &mynetif);
|
|
|
|
dhcps_delete(dhcps);
|
2018-05-14 09:03:37 -04:00
|
|
|
return 0;
|
|
|
|
}
|