fix: Responses without question RRs (i.e. REFUSED)

This commit is contained in:
Willem Toorop 2014-10-23 16:02:34 +02:00
parent 55e0d41d4b
commit 432092311e
2 changed files with 19 additions and 12 deletions

View File

@ -1005,13 +1005,14 @@ priv_getdns_create_reply_question_dict(
assert(pkt); assert(pkt);
assert(q_dict); assert(q_dict);
rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
if (! rr)
return GETDNS_RETURN_GENERIC_ERROR;
*q_dict = getdns_dict_create_with_context(context); *q_dict = getdns_dict_create_with_context(context);
if (! *q_dict) if (! *q_dict)
return GETDNS_RETURN_MEMORY_ERROR; return GETDNS_RETURN_MEMORY_ERROR;
rr = ldns_rr_list_rr(ldns_pkt_question(pkt), 0);
if (! rr)
return GETDNS_RETURN_GOOD;
do { /* break on error (to cleanup *q_dict) */ do { /* break on error (to cleanup *q_dict) */
r = getdns_dict_set_int(*q_dict, r = getdns_dict_set_int(*q_dict,
"qtype", ldns_rr_get_type(rr)); "qtype", ldns_rr_get_type(rr));

View File

@ -476,13 +476,18 @@ create_reply_dict(struct getdns_context *context, getdns_network_req * req,
} }
} }
/* other stuff */ /* other stuff
* Note that spec doesn't explicitely mention these.
* They are only showcased in the response dict example */
r = getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE, r = getdns_dict_set_int(result, GETDNS_STR_KEY_ANSWER_TYPE,
GETDNS_NAMETYPE_DNS); GETDNS_NAMETYPE_DNS);
if (r != GETDNS_RETURN_GOOD) { if (r != GETDNS_RETURN_GOOD) {
break; break;
} }
question = ldns_rr_list_rr(ldns_pkt_question(reply), 0); question = ldns_rr_list_rr(ldns_pkt_question(reply), 0);
/* Some packets (like with rcode REFUSED)
* don't even have RRs in the question section! */
if (question) {
name = convert_rdf_to_str(ldns_rr_owner(question)); name = convert_rdf_to_str(ldns_rr_owner(question));
if (! name) { if (! name) {
r = GETDNS_RETURN_MEMORY_ERROR; r = GETDNS_RETURN_MEMORY_ERROR;
@ -491,6 +496,7 @@ create_reply_dict(struct getdns_context *context, getdns_network_req * req,
r = getdns_dict_util_set_string(result, r = getdns_dict_util_set_string(result,
GETDNS_STR_KEY_CANONICAL_NM, name); GETDNS_STR_KEY_CANONICAL_NM, name);
free(name); free(name);
}
} while (0); } while (0);