Skip to content

Commit 196198e

Browse files
committed
fix(mdns): Fix zero-sized VLA clang-tidy warnings
and some minor leaks in creation of browse results
1 parent e838bf0 commit 196198e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

components/mdns/mdns.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,11 @@ static void _mdns_restart_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol
23552355
srv_count++;
23562356
a = a->next;
23572357
}
2358+
if (srv_count == 0) {
2359+
// proble only IP
2360+
_mdns_init_pcb_probe(tcpip_if, ip_protocol, NULL, 0, true);
2361+
return;
2362+
}
23582363
mdns_srv_item_t *services[srv_count];
23592364
size_t i = 0;
23602365
a = _mdns_server->services;
@@ -2555,6 +2560,10 @@ static void _mdns_restart_all_pcbs(void)
25552560
srv_count++;
25562561
a = a->next;
25572562
}
2563+
if (srv_count == 0) {
2564+
_mdns_probe_all_pcbs(NULL, 0, true, true);
2565+
return;
2566+
}
25582567
mdns_srv_item_t *services[srv_count];
25592568
size_t l = 0;
25602569
a = _mdns_server->services;
@@ -2898,11 +2907,12 @@ static int _mdns_check_srv_collision(mdns_service_t *service, uint16_t priority,
28982907
static int _mdns_check_txt_collision(mdns_service_t *service, const uint8_t *data, size_t len)
28992908
{
29002909
size_t data_len = 0;
2901-
if (len == 1 && service->txt) {
2910+
if (len <= 1 && service->txt) { // len==0 means incorrect packet (and handled by the packet parser)
2911+
// but handled here again to fix clang-tidy warning on VLA "uint8_t our[0];"
29022912
return -1;//we win
29032913
} else if (len > 1 && !service->txt) {
29042914
return 1;//they win
2905-
} else if (len == 1 && !service->txt) {
2915+
} else if (len <= 1 && !service->txt) {
29062916
return 0;//same
29072917
}
29082918

@@ -3788,7 +3798,7 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
37883798
mdns_class &= 0x7FFF;
37893799

37903800
content = data_ptr + data_len;
3791-
if (content > (data + len)) {
3801+
if (content > (data + len) || data_len == 0) {
37923802
goto clear_rx_packet;
37933803
}
37943804

@@ -4271,15 +4281,10 @@ void mdns_parse_packet(mdns_rx_packet_t *packet)
42714281
free(record);
42724282
}
42734283
free(parsed_packet);
4274-
if (browse_result_instance) {
4275-
free(browse_result_instance);
4276-
}
4277-
if (browse_result_service) {
4278-
free(browse_result_service);
4279-
}
4280-
if (browse_result_proto) {
4281-
free(browse_result_proto);
4282-
}
4284+
free(browse_result_instance);
4285+
free(browse_result_service);
4286+
free(browse_result_proto);
4287+
free(out_sync_browse);
42834288
}
42844289

42854290
/**

0 commit comments

Comments
 (0)