diff --git a/src/rr-dict.c b/src/rr-dict.c index 5807212c..d51382c0 100644 --- a/src/rr-dict.c +++ b/src/rr-dict.c @@ -1005,13 +1005,14 @@ priv_getdns_create_reply_question_dict( assert(pkt); 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); if (! *q_dict) 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) */ r = getdns_dict_set_int(*q_dict, "qtype", ldns_rr_get_type(rr)); diff --git a/src/util-internal.c b/src/util-internal.c index 41ef7537..4808ce20 100755 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -476,21 +476,27 @@ 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, GETDNS_NAMETYPE_DNS); if (r != GETDNS_RETURN_GOOD) { break; } question = ldns_rr_list_rr(ldns_pkt_question(reply), 0); - name = convert_rdf_to_str(ldns_rr_owner(question)); - if (! name) { - r = GETDNS_RETURN_MEMORY_ERROR; - break; + /* 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)); + if (! name) { + r = GETDNS_RETURN_MEMORY_ERROR; + break; + } + r = getdns_dict_util_set_string(result, + GETDNS_STR_KEY_CANONICAL_NM, name); + free(name); } - r = getdns_dict_util_set_string(result, - GETDNS_STR_KEY_CANONICAL_NM, name); - free(name); } while (0);