62#define FUZZ_DEBUG LWIP_DBG_OFF
65#ifdef LWIP_FUZZ_SYS_NOW
75#define FUZZ_DUMP_PCAP 0
79const u8_t pcap_file_header[24] = {
80 0xd4, 0xc3, 0xb2, 0xa1, 0x02, 0x00, 0x04, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00
86static u32_t pcap_packet;
90 fpcap =
fopen(FUZZ_DUMP_PCAP_FILE,
"wb");
93 fwrite(pcap_file_header, 1,
sizeof(pcap_file_header), fpcap);
110static void pcap_dump_packet(
struct pbuf *
p,
int is_tx)
120 if (pcap_packet == 50 || pcap_packet == 33 || pcap_packet == 29) {
126 fwrite(&pcap_packet, 1,
sizeof(pcap_packet), fpcap);
134 fwrite(
q->payload, 1,
q->len, fpcap);
141 pcap_dump_packet(
p, 0);
146 pcap_dump_packet(
p, 1);
149#define pcap_dump_rx_packet(p)
150#define pcap_dump_tx_packet(p)
151#define pcap_dump_init()
152#define pcap_dump_stop()
168 netif->output = etharp_output;
182 netif->output_ip6 = ethip6_output;
183 netif_create_ip6_linklocal_address(
netif, 1);
196 printf(
"pkt too big (%#zX bytes)\n",
len);
223 const u16_t max_packet_size = 1514;
228#ifdef LWIP_FUZZ_SYS_NOW
229 u32_t external_delay = 0;
232#ifdef LWIP_FUZZ_SYS_NOW
235 external_delay =
ntohl(external_delay);
243 frame_len =
ntohs(frame_len) & 0x7FF;
244 frame_len =
LWIP_MIN(frame_len, max_packet_size);
248 if (frame_len != 0) {
250#ifdef LWIP_FUZZ_SYS_NOW
252 sys_now_offset += external_delay;
255 sys_check_timeouts();
259 sys_check_timeouts();
268static u16_t tcp_remote_port;
269static u16_t tcp_local_port;
284 const u16_t max_data_size = 65495;
290 data_len =
ntohs(data_len);
291 data_len =
LWIP_MIN(data_len, max_data_size);
321 tcp_app_fuzz_input(pcb);
341 tcp_app_fuzz_input(pcb);
399 tcp_app_fuzz_input(pcb);
469static struct udp_pcb *udp_client_pcb;
470static struct udp_pcb *udp_server_pcb;
471static u16_t udp_remote_port;
472static u16_t udp_local_port;
487 const u16_t max_data_size = 65507;
493 data_len =
ntohs(data_len);
494 data_len =
LWIP_MIN(data_len, max_data_size);
552 udp_app_fuzz_input(pcb,
NULL,
port);
570 udp_app_fuzz_input(pcb,
addr,
port);
590 IP4_ADDR(&
addr, 172, 30, 115, 84);
591 IP4_ADDR(&netmask, 255, 255, 255, 0);
592 IP4_ADDR(&gw, 172, 30, 115, 1);
600 IP_ADDR4(&remote_addr, 172, 30, 115, 37);
601 etharp_add_static_entry(&(remote_addr.u_addr.ip4), &remote_mac);
614 mdns_resp_add_netif(&
net_test,
"hostname");
620 tcp_remote_port = 80;
621 err =
altcp_connect(tcp_client_pcb, &remote_addr, tcp_remote_port, tcp_client_connected);
624 altcp_err(tcp_client_pcb, tcp_client_err);
625 altcp_poll(tcp_client_pcb, tcp_client_poll, 10);
640 udp_client_pcb = udp_new();
642 udp_recv(udp_client_pcb, udp_client_recv,
NULL);
643 udp_remote_port = 161;
644 udp_connect(udp_client_pcb, &remote_addr, udp_remote_port);
647 udp_server_pcb = udp_new();
649 udp_local_port = 161;
650 udp_bind(udp_server_pcb,
IP_ANY_TYPE, udp_local_port);
651 udp_recv(udp_server_pcb, udp_server_recv,
NULL);
657 printf(
"reading input from file... ");
675#ifdef LWIP_RAND_FOR_FUZZ
676u32_t lwip_fuzz_rand(
void)
678#ifdef LWIP_RAND_FOR_FUZZ_SIMULATE_GLIBC
680 static u32_t rand_nrs[] = {0x6b8b4567, 0x327b23c6, 0x643c9869, 0x66334873, 0x74b0dc51,
681 0x19495cff, 0x2ae8944a, 0x625558ec, 0x238e1f29, 0x46e87ccd,
682 0x3d1b58ba, 0x507ed7ab, 0x2eb141f2, 0x41b71efb, 0x79e2a9e3,
683 0x7545e146, 0x515f007c, 0x5bd062c2, 0x12200854, 0x4db127f8};
684 static unsigned idx = 0;
687 if (
idx >=
sizeof(rand_nrs)/
sizeof((rand_nrs)[0])) {
696 val = ((
val * 1103515245) + 12345) & 0x7fffffff;
#define altcp_tcp_new_ip_type
#define LWIP_DEBUGF(debug, message)
#define LWIP_ASSERT(message, assertion)
static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
int lwip_fuzztest(int argc, char **argv, enum lwip_fuzz_type type, u32_t test_apps)
#define pcap_dump_rx_packet(p)
#define pcap_dump_tx_packet(p)
static u8_t pktbuf[200000]
static void input_pkts(enum lwip_fuzz_type type, struct netif *netif, const u8_t *data, size_t len)
static size_t remfuzz_len
static void input_pkt(struct netif *netif, const u8_t *data, size_t len)
static const u8_t * remfuzz_ptr
static err_t testif_init(struct netif *netif)
#define LWIP_FUZZ_UDP_CLIENT
@ LWIP_FUZZ_MULTIPACKET_TIME
#define LWIP_FUZZ_UDP_SERVER
#define LWIP_FUZZ_DEFAULT
#define LWIP_FUZZ_STATICARP
#define LWIP_FUZZ_TCP_CLIENT
#define LWIP_FUZZ_TCP_SERVER
GLuint GLuint GLsizei GLenum type
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble GLdouble q
GLenum const GLvoid * addr
#define LWIP_UNUSED_ARG(x)
#define NETIF_FLAG_ETHARP
#define NETIF_FLAG_BROADCAST
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
void netif_set_link_up(struct netif *netif)
void netif_set_up(struct netif *netif)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
u8_t pbuf_free(struct pbuf *p)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define ETH_ADDR(b0, b1, b2, b3, b4, b5)
void * lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void *report_arg)
#define MEMCPY(DST, SRC, BYTES)
#define memcpy(s1, s2, n)
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
netif_linkoutput_fn linkoutput
static struct netif net_test