Merge branch 'bugfix/mdns_crash_free_strdup_3.2_fix' into 'release/v3.2'
mdns: fixed crash on free undefined ptr if strdup is skipped (Backport 3.2 FIX) See merge request idf/esp-idf!4197
This commit is contained in:
commit
807ef53c38
1 changed files with 13 additions and 10 deletions
|
@ -2487,15 +2487,19 @@ handle_error :
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Duplicate string or return NULL
|
* @brief Duplicate string or return error
|
||||||
*/
|
*/
|
||||||
static char * _mdns_strdup_check(const char * in)
|
static esp_err_t _mdns_strdup_check(char ** out, char * in)
|
||||||
{
|
{
|
||||||
if (in && in[0]) {
|
if (in && in[0]) {
|
||||||
return strdup(in);
|
*out = strdup(in);
|
||||||
} else {
|
if (!*out) {
|
||||||
return NULL;
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
*out = NULL;
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2624,11 +2628,10 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
||||||
|
|
||||||
question->unicast = unicast;
|
question->unicast = unicast;
|
||||||
question->type = type;
|
question->type = type;
|
||||||
question->host = _mdns_strdup_check(name->host);
|
if (_mdns_strdup_check(&(question->host), name->host)
|
||||||
question->service = _mdns_strdup_check(name->service);
|
|| _mdns_strdup_check(&(question->service), name->service)
|
||||||
question->proto = _mdns_strdup_check(name->proto);
|
|| _mdns_strdup_check(&(question->proto), name->proto)
|
||||||
question->domain = _mdns_strdup_check(name->domain);
|
|| _mdns_strdup_check(&(question->domain), name->domain)) {
|
||||||
if (!question->host || !question->service || !question->proto || !question->domain) {
|
|
||||||
goto clear_rx_packet;
|
goto clear_rx_packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue