mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-16 20:12:13 +02:00
mdns: Update fuzzer test (add delegation, check memory)
* Add new config with no services * Add new test packets and more queries * Allocate packet to check for mem issues * Original commit: espressif/esp-idf@2c1007156e
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
5909e9e54c
commit
ec03fec3d3
@ -40,6 +40,10 @@ CFLAGS=-g -Wno-unused-value -Wno-missing-declarations -Wno-pointer-bool-conversi
|
|||||||
|
|
||||||
|
|
||||||
MDNS_C_DEPENDENCY_INJECTION=-include mdns_di.h
|
MDNS_C_DEPENDENCY_INJECTION=-include mdns_di.h
|
||||||
|
ifeq ($(MDNS_NO_SERVICES),on)
|
||||||
|
CFLAGS+=-DMDNS_NO_SERVICES
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(INSTR),off)
|
ifeq ($(INSTR),off)
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS+=-DINSTR_IS_OFF
|
CFLAGS+=-DINSTR_IS_OFF
|
||||||
|
BIN
components/mdns/test_afl_fuzz_host/in/file2.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/file2.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_4a_txt.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_4a_txt.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_aaaa.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_aaaa.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_any.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_any.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_disc.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_disc.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_ptr.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_ptr.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_query.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_query.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/minif_query2.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/minif_query2.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/sub_fritz_m.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/sub_fritz_m.bin
Normal file
Binary file not shown.
BIN
components/mdns/test_afl_fuzz_host/in/telnet_ptr.bin
Normal file
BIN
components/mdns/test_afl_fuzz_host/in/telnet_ptr.bin
Normal file
Binary file not shown.
@ -1,16 +1,8 @@
|
|||||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
/*
|
||||||
//
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
// you may not use this file except in compliance with the License.
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -36,11 +28,14 @@ mdns_search_once_t * mdns_test_search_init(const char * name, const char * servi
|
|||||||
esp_err_t mdns_test_send_search_action(mdns_action_type_t type, mdns_search_once_t * search);
|
esp_err_t mdns_test_send_search_action(mdns_action_type_t type, mdns_search_once_t * search);
|
||||||
void mdns_test_search_free(mdns_search_once_t * search);
|
void mdns_test_search_free(mdns_search_once_t * search);
|
||||||
void mdns_test_init_di(void);
|
void mdns_test_init_di(void);
|
||||||
|
extern mdns_server_t * _mdns_server;
|
||||||
|
|
||||||
//
|
//
|
||||||
// mdns function wrappers for mdns setup in test mode
|
// mdns function wrappers for mdns setup in test mode
|
||||||
static int mdns_test_hostname_set(const char * mdns_hostname)
|
static int mdns_test_hostname_set(const char * mdns_hostname)
|
||||||
{
|
{
|
||||||
|
_mdns_server->interfaces[MDNS_IF_STA].pcbs[MDNS_IP_PROTOCOL_V4].state = PCB_RUNNING; // mark the PCB running to exercise mdns in fully operational mode
|
||||||
|
_mdns_server->interfaces[MDNS_IF_STA].pcbs[MDNS_IP_PROTOCOL_V6].state = PCB_RUNNING;
|
||||||
int ret = mdns_hostname_set(mdns_hostname);
|
int ret = mdns_hostname_set(mdns_hostname);
|
||||||
mdns_action_t * a = NULL;
|
mdns_action_t * a = NULL;
|
||||||
GetLastItem(&a);
|
GetLastItem(&a);
|
||||||
@ -48,6 +43,18 @@ static int mdns_test_hostname_set(const char * mdns_hostname)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mdns_test_add_delegated_host(const char * mdns_hostname)
|
||||||
|
{
|
||||||
|
mdns_ip_addr_t addr = { .addr = { .u_addr = ESP_IPADDR_TYPE_V4 } };
|
||||||
|
addr.addr.u_addr.ip4.addr = 0x11111111;
|
||||||
|
int ret = mdns_delegate_hostname_add(mdns_hostname, &addr);
|
||||||
|
mdns_action_t * a = NULL;
|
||||||
|
GetLastItem(&a);
|
||||||
|
mdns_test_execute_action(a);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int mdns_test_service_instance_name_set(const char * service, const char * proto, const char * instance)
|
static int mdns_test_service_instance_name_set(const char * service, const char * proto, const char * instance)
|
||||||
{
|
{
|
||||||
int ret = mdns_service_instance_name_set(service, proto, instance);
|
int ret = mdns_service_instance_name_set(service, proto, instance);
|
||||||
@ -66,6 +73,25 @@ static int mdns_test_service_txt_set(const char * service, const char * proto,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mdns_test_sub_service_add(const char * sub_name, const char * service_name, const char * proto, uint32_t port)
|
||||||
|
{
|
||||||
|
if (mdns_service_add(NULL, service_name, proto, port, NULL, 0)) {
|
||||||
|
// This is expected failure as the service thread is not running
|
||||||
|
}
|
||||||
|
mdns_action_t * a = NULL;
|
||||||
|
GetLastItem(&a);
|
||||||
|
mdns_test_execute_action(a);
|
||||||
|
|
||||||
|
if (mdns_test_mdns_get_service_item(service_name, proto)==NULL) {
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
int ret = mdns_service_subtype_add_for_host(NULL, service_name, proto, NULL, sub_name);
|
||||||
|
a = NULL;
|
||||||
|
GetLastItem(&a);
|
||||||
|
mdns_test_execute_action(a);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int mdns_test_service_add(const char * service_name, const char * proto, uint32_t port)
|
static int mdns_test_service_add(const char * service_name, const char * proto, uint32_t port)
|
||||||
{
|
{
|
||||||
if (mdns_service_add(NULL, service_name, proto, port, NULL, 0)) {
|
if (mdns_service_add(NULL, service_name, proto, port, NULL, 0)) {
|
||||||
@ -81,9 +107,9 @@ static int mdns_test_service_add(const char * service_name, const char * proto,
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static mdns_result_t* mdns_test_query(const char * service_name, const char * proto)
|
static mdns_result_t* mdns_test_query(const char * name, const char * service, const char * proto, uint16_t type)
|
||||||
{
|
{
|
||||||
search = mdns_test_search_init(NULL, service_name, proto, MDNS_TYPE_PTR, 3000, 20);
|
search = mdns_test_search_init(name, service, proto, type, 3000, 20);
|
||||||
if (!search) {
|
if (!search) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -142,6 +168,20 @@ int main(int argc, char** argv)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mdns_test_add_delegated_host(mdns_hostname) || mdns_test_add_delegated_host("megafritz")) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef MDNS_NO_SERVICES
|
||||||
|
|
||||||
|
if (mdns_test_sub_service_add("_server", "_fritz", "_tcp", 22)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mdns_test_service_add("_telnet", "_tcp", 22)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
if (mdns_test_service_add("_workstation", "_tcp", 9)) {
|
if (mdns_test_service_add("_workstation", "_tcp", 9)) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -186,7 +226,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
mdns_result_t * results = NULL;
|
mdns_result_t * results = NULL;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
size_t nread;
|
size_t nread;
|
||||||
@ -216,12 +256,22 @@ int main(int argc, char** argv)
|
|||||||
memset(buf, 0, 1460);
|
memset(buf, 0, 1460);
|
||||||
size_t len = read(0, buf, 1460);
|
size_t len = read(0, buf, 1460);
|
||||||
#endif
|
#endif
|
||||||
mypbuf.payload = buf;
|
mypbuf.payload = malloc(len);
|
||||||
|
memcpy(mypbuf.payload, buf, len);
|
||||||
mypbuf.len = len;
|
mypbuf.len = len;
|
||||||
g_packet.pb = &mypbuf;
|
g_packet.pb = &mypbuf;
|
||||||
mdns_test_query("_afpovertcp", "_tcp");
|
mdns_test_query("minifritz", "_fritz", "_tcp", MDNS_TYPE_ANY);
|
||||||
|
mdns_test_query(NULL, "_fritz", "_tcp", MDNS_TYPE_PTR);
|
||||||
|
mdns_test_query(NULL, "_afpovertcp", "_tcp", MDNS_TYPE_PTR);
|
||||||
mdns_parse_packet(&g_packet);
|
mdns_parse_packet(&g_packet);
|
||||||
|
free(mypbuf.payload);
|
||||||
}
|
}
|
||||||
|
#ifndef MDNS_NO_SERVICES
|
||||||
|
mdns_service_remove_all();
|
||||||
|
mdns_action_t *a = NULL;
|
||||||
|
GetLastItem(&a);
|
||||||
|
mdns_test_execute_action(a);
|
||||||
|
#endif
|
||||||
ForceTaskDelete();
|
ForceTaskDelete();
|
||||||
mdns_free();
|
mdns_free();
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user