mirror of https://github.com/getdnsapi/getdns.git
Fix a bug in list copy for bindata. Fix some memory errors
This commit is contained in:
parent
dfa5fc82c8
commit
840939aac8
|
@ -37,12 +37,12 @@ main()
|
|||
{
|
||||
getdns_return_t context_create_return;
|
||||
struct getdns_list *just_the_addresses_ptr;
|
||||
size_t *num_addresses_ptr = NULL;
|
||||
size_t num_addresses = 0;
|
||||
size_t rec_count;
|
||||
struct getdns_dict *this_address;
|
||||
struct getdns_bindata *this_address_data;
|
||||
struct getdns_context_t *this_context = NULL;
|
||||
uint32_t *this_error = NULL;
|
||||
uint32_t this_error = 0;
|
||||
struct getdns_dict *this_extensions = NULL;
|
||||
const char *this_name = "www.example.com";
|
||||
uint8_t this_request_type = GETDNS_RRTYPE_A;
|
||||
|
@ -79,22 +79,21 @@ main()
|
|||
else
|
||||
{
|
||||
/* Be sure the search returned something */
|
||||
this_ret = getdns_dict_get_int(this_response, "status", this_error); // Ignore any error
|
||||
if (this_error && (*this_error != GETDNS_RESPSTATUS_GOOD)) // If the search didn't return "good"
|
||||
this_ret = getdns_dict_get_int(this_response, "status", &this_error); // Ignore any error
|
||||
if (this_error != GETDNS_RESPSTATUS_GOOD) // If the search didn't return "good"
|
||||
{
|
||||
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", *this_error);
|
||||
fprintf(stderr, "The search had no results, and a return value of %d. Exiting.", this_error);
|
||||
return(GETDNS_RETURN_GENERIC_ERROR);
|
||||
}
|
||||
this_ret = getdns_dict_get_list(this_response, "just_address_answers", &just_the_addresses_ptr); // Ignore any error
|
||||
this_ret = getdns_list_get_length(just_the_addresses_ptr, num_addresses_ptr); // Ignore any error
|
||||
this_ret = getdns_list_get_length(just_the_addresses_ptr, &num_addresses); // Ignore any error
|
||||
/* Go through each record */
|
||||
if (num_addresses_ptr) {
|
||||
for (rec_count = 0; rec_count <= *num_addresses_ptr; ++rec_count )
|
||||
if (num_addresses > 0) {
|
||||
for (rec_count = 0; rec_count < num_addresses; ++rec_count )
|
||||
{
|
||||
this_ret = getdns_list_get_dict(just_the_addresses_ptr, rec_count, &this_address); // Ignore any error
|
||||
this_ret = getdns_list_get_bindata(just_the_addresses_ptr, rec_count, &this_address_data); // Ignore any error
|
||||
/* Just print the address */
|
||||
this_ret = getdns_dict_get_bindata(this_address, "address_data", &this_address_data); // Ignore any error
|
||||
printf("The address is %s", getdns_display_ip_address(this_address_data));
|
||||
printf("The address is %s\n", getdns_display_ip_address(this_address_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,8 +208,8 @@ getdns_list_copy(struct getdns_list *srclist, struct getdns_list **dstlist)
|
|||
(*dstlist)->items[i].data.bindata->data = (uint8_t *)
|
||||
malloc(srclist->items[i].data.bindata->size);
|
||||
if((*dstlist)->items[i].data.bindata->data != NULL)
|
||||
memcpy(srclist->items[i].data.bindata->data
|
||||
, (*dstlist)->items[i].data.bindata->data
|
||||
memcpy((*dstlist)->items[i].data.bindata->data,
|
||||
srclist->items[i].data.bindata->data
|
||||
, srclist->items[i].data.bindata->size);
|
||||
else
|
||||
retval = GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
|
13
src/sync.c
13
src/sync.c
|
@ -33,6 +33,7 @@
|
|||
#include <unbound-event.h>
|
||||
#include "context.h"
|
||||
#include "general.h"
|
||||
#include <string.h>
|
||||
|
||||
/* stuff to make it compile pedantically */
|
||||
#define UNUSED_PARAM(x) ((void)(x))
|
||||
|
@ -40,7 +41,7 @@
|
|||
/* struct used for the request */
|
||||
typedef struct sync_request_data {
|
||||
getdns_context_t context;
|
||||
const char* name;
|
||||
char* name;
|
||||
uint16_t request_type;
|
||||
getdns_dict *extensions;
|
||||
getdns_return_t response_status;
|
||||
|
@ -85,11 +86,12 @@ getdns_general_sync(
|
|||
{
|
||||
/* we will cheat and spawn a thread */
|
||||
/* set up for sync resolution */
|
||||
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
sync_request_data req_data = {
|
||||
context, name, request_type,
|
||||
context,
|
||||
strdup(name),
|
||||
request_type,
|
||||
extensions,
|
||||
GETDNS_RETURN_GOOD,
|
||||
response
|
||||
|
@ -98,11 +100,13 @@ getdns_general_sync(
|
|||
/* create the thread */
|
||||
int ret = pthread_attr_init(&attr);
|
||||
if (ret != 0) {
|
||||
free(req_data.name);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
ret = pthread_create(&thread, &attr, request_thread_start, &req_data);
|
||||
if (ret != 0) {
|
||||
pthread_attr_destroy(&attr);
|
||||
free(req_data.name);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
/* wait for the thread */
|
||||
|
@ -110,9 +114,10 @@ getdns_general_sync(
|
|||
/* delete attr */
|
||||
pthread_attr_destroy(&attr);
|
||||
if (ret != 0) {
|
||||
free(req_data.name);
|
||||
return GETDNS_RETURN_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
free(req_data.name);
|
||||
return req_data.response_status;
|
||||
}
|
||||
|
||||
|
|
|
@ -231,6 +231,7 @@ static getdns_dict *create_dict_from_rr(ldns_rr* rr) {
|
|||
if (rd_count >= 1) {
|
||||
getdns_dict* rdata = create_dict_from_rdf(ldns_rr_rdf(rr, 0));
|
||||
r |= getdns_dict_set_dict(result, GETDNS_STR_KEY_RDATA, rdata);
|
||||
getdns_dict_destroy(rdata);
|
||||
}
|
||||
/* TODO - if more than one, is rdata a list? */
|
||||
|
||||
|
@ -251,8 +252,10 @@ static getdns_list *create_list_from_rr_list(ldns_rr_list* rr_list) {
|
|||
getdns_list *result = getdns_list_create();
|
||||
for (i = 0; i < ldns_rr_list_rr_count(rr_list); ++i) {
|
||||
ldns_rr *rr = ldns_rr_list_rr(rr_list, i);
|
||||
getdns_dict* rrdict = create_dict_from_rr(rr);
|
||||
r |= getdns_list_add_item(result, &idx);
|
||||
r |= getdns_list_set_dict(result, idx, create_dict_from_rr(rr));
|
||||
r |= getdns_list_set_dict(result, idx, rrdict);
|
||||
getdns_dict_destroy(rrdict);
|
||||
}
|
||||
if (r != 0) {
|
||||
getdns_list_destroy(result);
|
||||
|
@ -272,9 +275,12 @@ static getdns_return_t add_only_addresses(getdns_list* addrs, ldns_rr_list* rr_l
|
|||
for (j = 0; j < rd_count; ++j) {
|
||||
size_t item_idx = 0;
|
||||
ldns_rdf* rdf = ldns_rr_rdf(rr, j);
|
||||
getdns_bindata rbin = { ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
|
||||
r |= getdns_list_add_item(addrs, &item_idx);
|
||||
r |= getdns_list_set_bindata(addrs, item_idx, &rbin);
|
||||
if (ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_A ||
|
||||
ldns_rdf_get_type(rdf) == LDNS_RDF_TYPE_AAAA) {
|
||||
getdns_bindata rbin = { ldns_rdf_size(rdf), ldns_rdf_data(rdf) };
|
||||
r |= getdns_list_add_item(addrs, &item_idx);
|
||||
r |= getdns_list_set_bindata(addrs, item_idx, &rbin);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
|
@ -424,6 +430,7 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
|
|||
getdns_dict *reply = create_reply_dict(netreq, just_addrs);
|
||||
r |= getdns_list_add_item(replies_tree, &idx);
|
||||
r |= getdns_list_set_dict(replies_tree, idx, reply);
|
||||
getdns_dict_destroy(reply);
|
||||
/* buffer */
|
||||
if (s == LDNS_STATUS_OK) {
|
||||
r |= getdns_list_add_item(replies_full, &idx);
|
||||
|
@ -441,6 +448,11 @@ getdns_dict *create_getdns_response(struct getdns_dns_req* completed_request) {
|
|||
if (just_addrs) {
|
||||
r |= getdns_dict_set_list(result, GETDNS_STR_KEY_JUST_ADDRS, just_addrs);
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
getdns_list_destroy(replies_tree);
|
||||
getdns_list_destroy(replies_full);
|
||||
getdns_list_destroy(just_addrs);
|
||||
|
||||
if (r != 0) {
|
||||
getdns_dict_destroy(result);
|
||||
|
|
Loading…
Reference in New Issue