Skip to content

Commit 3dadce2

Browse files
committed
fix(mdns): remove the the range of MDNS_MAX_SERVICES and fix issues of string functions
1 parent 27303d2 commit 3dadce2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

components/mdns/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ menu "mDNS"
1010

1111
config MDNS_MAX_SERVICES
1212
int "Max number of services"
13-
range 1 64
1413
default 10
1514
help
1615
Services take up a certain amount of memory, and allowing fewer
1716
services to be open at the same time conserves memory. Specify
18-
the maximum amount of services here. The valid value is from 1
19-
to 64.
17+
the maximum amount of services here.
2018

2119
config MDNS_TASK_PRIORITY
2220
int "mDNS task priority"

components/mdns/mdns.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5595,9 +5595,14 @@ esp_err_t mdns_hostname_set(const char *hostname)
55955595

55965596
esp_err_t mdns_hostname_get(char *hostname)
55975597
{
5598-
if (!_mdns_server || !hostname) {
5598+
if (!hostname) {
55995599
return ESP_ERR_INVALID_ARG;
56005600
}
5601+
5602+
if (!_mdns_server || !_mdns_server->hostname) {
5603+
return ESP_ERR_INVALID_STATE;
5604+
}
5605+
56015606
MDNS_SERVICE_LOCK();
56025607
strncpy(hostname, _mdns_server->hostname, strnlen(_mdns_server->hostname, MDNS_NAME_BUF_LEN));
56035608
MDNS_SERVICE_UNLOCK();
@@ -5900,10 +5905,14 @@ static mdns_result_t *_mdns_lookup_service(const char *instance, const char *ser
59005905
item->esp_netif = NULL;
59015906
item->ttl = _str_null_or_empty(instance) ? MDNS_ANSWER_PTR_TTL : MDNS_ANSWER_SRV_TTL;
59025907
item->ip_protocol = MDNS_IP_PROTOCOL_MAX;
5903-
item->instance_name = strndup(srv->instance, MDNS_NAME_BUF_LEN - 1);
5904-
if (!item->instance_name) {
5905-
HOOK_MALLOC_FAILED;
5906-
goto handle_error;
5908+
if (srv->instance) {
5909+
item->instance_name = strndup(srv->instance, MDNS_NAME_BUF_LEN - 1);
5910+
if (!item->instance_name) {
5911+
HOOK_MALLOC_FAILED;
5912+
goto handle_error;
5913+
}
5914+
} else {
5915+
item->instance_name = NULL;
59075916
}
59085917
item->service_type = strndup(srv->service, MDNS_NAME_BUF_LEN - 1);
59095918
if (!item->service_type) {

0 commit comments

Comments
 (0)