Close #2200: Ignore/discard DNS SRV response with truncated flag set.

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@6000 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Riza Sulistyo 2019-05-23 13:42:27 +00:00
parent d53bc8244c
commit e3d314f7d1
2 changed files with 28 additions and 9 deletions

View File

@ -1776,9 +1776,12 @@ static void on_read_complete(pj_ioqueue_key_t *key,
/* Workaround for deadlock problem in #1108 */
pj_grp_lock_acquire(resolver->grp_lock);
/* Save/update response cache. */
update_res_cache(resolver, &q->key, status, PJ_TRUE, dns_pkt);
/* Truncated responses MUST NOT be saved (cached). */
if (PJ_DNS_GET_TC(dns_pkt->hdr.flags) == 0) {
/* Save/update response cache. */
update_res_cache(resolver, &q->key, status, PJ_TRUE, dns_pkt);
}
/* Recycle query objects, starting with the child queries */
if (!pj_list_empty(&q->child_head)) {
pj_dns_async_query *child_q;

View File

@ -585,13 +585,29 @@ static void dns_callback(void *user_data,
/* Clear the outstanding job */
query_job->q_srv = NULL;
if (status == PJ_SUCCESS && pkt->hdr.anscount != 0) {
/* Got SRV response, build server entry. If A records are available
* in additional records section of the DNS response, save them too.
*/
build_server_entries(query_job, pkt);
if (status == PJ_SUCCESS) {
if (PJ_DNS_GET_TC(pkt->hdr.flags)) {
/* Got truncated answer, the standard recommends to follow up
* the query using TCP. Since we currently don't support it,
* just return error.
*/
PJ_LOG(4,(query_job->objname,
"Discard truncated DNS SRV response for %.*s",
(int)query_job->full_name.slen,
query_job->full_name.ptr));
} else if (status != PJ_SUCCESS) {
status = PJ_EIGNORED;
query_job->last_error = status;
goto on_error;
} else if (pkt->hdr.anscount != 0) {
/* Got SRV response, build server entry. If A records are
* available in additional records section of the DNS response,
* save them too.
*/
build_server_entries(query_job, pkt);
}
} else {
char errmsg[PJ_ERR_MSG_SIZE];
/* Update query_job last error */