mDNS crash when functions called in wrong order

cruvus
Posts: 60
Joined: Fri Jul 08, 2022 5:08 pm
Location: Planet Earth

mDNS crash when functions called in wrong order

Postby cruvus » Fri Jul 22, 2022 10:11 pm

The correct order to call the functions is:
mdns_init
mdns_hostname_set
mdns_instance_name_set
mdns_service_add

When we call them like this:
mdns_init
mdns_service_add
mdns_hostname_set
mdns_instance_name_set

The IDF crashes with a LoadProhibited. And it costs hours to find out the wrong order is the problem...

My opinion is, there should be an error message tops, but no crash.

cruvus
Posts: 60
Joined: Fri Jul 08, 2022 5:08 pm
Location: Planet Earth

Re: mDNS crash when functions called in wrong order

Postby cruvus » Fri Jul 22, 2022 10:50 pm

Minimum code example:

Code: Select all

#include "esp_log.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "mdns.h"

static const char *TAG = "main";

void app_main(void) {
	nvs_flash_init();
	esp_netif_init();
	esp_event_loop_create_default();

	esp_netif_create_default_wifi_sta();
	wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
	esp_wifi_init(&wifi_init_config);
	esp_wifi_start();
	esp_wifi_connect();

	mdns_init();
	mdns_service_add(NULL, "_http", "_tcp", 80, NULL, 0);

	ESP_LOGI(TAG, "mdns_hostname_set...");
	mdns_hostname_set("crashme");
}
Typical output:
I (00:00:02.451) main: mdns_hostname_set...
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x40001277 PS : 0x00060c30 A0 : 0x800d65eb A1 : 0x3ffc7080
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000001 A5 : 0x00000001
A6 : 0x3ffc5f00 A7 : 0x00000000 A8 : 0x00000001 A9 : 0x00000000
A10 : 0x00060c23 A11 : 0x00000000 A12 : 0x00000001 A13 : 0x00060c23
A14 : 0x00000003 A15 : 0x00060023 SAR : 0x0000000f EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff


Backtrace:0x40001274:0x3ffc70800x400d65e8:0x3ffc7090 0x400dbac8:0x3ffc70b0 0x400dbdf6:0x3ffc70f0 0x4008b87a:0x3ffc7120
0x400d65e8: _mdns_remap_self_service_hostname at C:/Users/***/esp/esp-idf/components/mdns/mdns.c:4226

0x400dbac8: _mdns_execute_action at C:/Users/***/esp/esp-idf/components/mdns/mdns.c:4307

0x400dbdf6: _mdns_service_task at C:/Users/***/esp/esp-idf/components/mdns/mdns.c:4596

0x4008b87a: vPortTaskWrapper at C:/Users/***/esp/esp-idf/components/freertos/port/xtensa/port.c:131

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: mDNS crash when functions called in wrong order

Postby ESP_Sprite » Sat Jul 23, 2022 1:28 am

Thanks, I created an internal issue for this. Note that if it's all the same to you, next time we 'd prefer it if you create an issue on the ESP-IDF Github as that gets tracked automatically.

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: mDNS crash when functions called in wrong order

Postby ESP_cermak » Fri Aug 19, 2022 4:56 pm

Thanks for reporting this problem (sorry for the delay & sorry for the inconvenience). I agree that mDNS API should be improved.

Although it's mentioned in the example:

https://github.com/espressif/esp-idf/bl ... .c#L41-L42

That if you want to advertize services it's required to configure hostname, we should not null dereference pointers and variables, but gracefully report errors. I've posted a PR fixing the issue here https://github.com/espressif/esp-protocols/pull/117

Who is online

Users browsing this forum: No registered users and 111 guests