mirror of https://github.com/getdnsapi/getdns.git
Allow to set empty bindata's
quite common in OPT record's rdata_raw
This commit is contained in:
parent
fafbcee2d4
commit
0daa5b573d
|
@ -1662,33 +1662,41 @@ struct getdns_bindata *
|
|||
getdns_bindata_copy(struct mem_funcs *mfs,
|
||||
const struct getdns_bindata *src)
|
||||
{
|
||||
struct getdns_bindata *dst;
|
||||
/* Don't know why, but nodata allows
|
||||
* empty bindatas with the python bindings
|
||||
*/
|
||||
static uint8_t nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
struct getdns_bindata *dst;
|
||||
|
||||
if (!src)
|
||||
return NULL;
|
||||
if (!src)
|
||||
return NULL;
|
||||
|
||||
dst = GETDNS_MALLOC(*mfs, struct getdns_bindata);
|
||||
if (!dst)
|
||||
return NULL;
|
||||
if (!(dst = GETDNS_MALLOC(*mfs, struct getdns_bindata)))
|
||||
return NULL;
|
||||
|
||||
dst->size = src->size;
|
||||
dst->data = GETDNS_XMALLOC(*mfs, uint8_t, src->size);
|
||||
if (!dst->data) {
|
||||
GETDNS_FREE(*mfs, dst);
|
||||
return NULL;
|
||||
}
|
||||
(void) memcpy(dst->data, src->data, src->size);
|
||||
return dst;
|
||||
dst->size = src->size;
|
||||
if ((dst->size = src->size)) {
|
||||
dst->data = GETDNS_XMALLOC(*mfs, uint8_t, src->size);
|
||||
if (!dst->data) {
|
||||
GETDNS_FREE(*mfs, dst);
|
||||
return NULL;
|
||||
}
|
||||
(void) memcpy(dst->data, src->data, src->size);
|
||||
} else {
|
||||
dst->data = nodata;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void
|
||||
getdns_bindata_destroy(struct mem_funcs *mfs,
|
||||
struct getdns_bindata *bindata)
|
||||
{
|
||||
if (!bindata)
|
||||
return;
|
||||
GETDNS_FREE(*mfs, bindata->data);
|
||||
GETDNS_FREE(*mfs, bindata);
|
||||
if (!bindata)
|
||||
return;
|
||||
|
||||
if (bindata->size) GETDNS_FREE(*mfs, bindata->data);
|
||||
GETDNS_FREE(*mfs, bindata);
|
||||
}
|
||||
|
||||
/* TODO: Remove next_timeout argument from getdns_context_get_num_pending_requests
|
||||
|
|
|
@ -1350,6 +1350,7 @@ getdns_return_t priv_getdns_append_opt_rr(
|
|||
|
||||
rdata.size = ldns_rdf_size(edns_data);
|
||||
rdata.data = ldns_rdf_data(edns_data);
|
||||
|
||||
} else {
|
||||
if (!(opt_rr = getdns_dict_create_with_context(context)))
|
||||
r |= GETDNS_RETURN_GENERIC_ERROR;
|
||||
|
@ -1363,11 +1364,13 @@ getdns_return_t priv_getdns_append_opt_rr(
|
|||
r |= getdns_dict_set_list(opt_rr, "options", options);
|
||||
getdns_list_destroy(options);
|
||||
}
|
||||
|
||||
/* add data */
|
||||
r |= getdns_dict_set_bindata(opt_rr, "rdata_raw", &rdata);
|
||||
r |= getdns_dict_set_dict(rr_dict, "rdata", opt_rr);
|
||||
getdns_dict_destroy(opt_rr);
|
||||
|
||||
|
||||
/* add rest of the fields */
|
||||
r |= getdns_dict_set_int(rr_dict, "type", GETDNS_RRTYPE_OPT);
|
||||
r |= getdns_dict_set_int(rr_dict, "udp_payload_size",
|
||||
|
|
Loading…
Reference in New Issue