offset += length;
Y = BN_bin2bn(key+offset, (int)length, NULL);
- offset += length;
/* create the key and set its properties */
if(!Q || !P || !G || !Y || !(dsa = DSA_new())) {
; hashmap_node != LDNS_RBTREE_NULL
; hashmap_node = ldns_rbtree_next(hashmap_node)
) {
- current_name = (ldns_dnssec_name *) hashmap_node->data;
nsec_rr = ((ldns_dnssec_name *) hashmap_node->data)->nsec;
if (nsec_rr) {
ldns_rr_list_push_rr(nsec3_list, nsec_rr);
cur_status = ldns_verify_rrsig_time(
cur_rrset, cur_sig_rr,
cur_parent_rr, check_time);
- (void) ldns_dnssec_trust_tree_add_parent(new_tree,
- cur_parent_tree, cur_sig_rr, cur_status);
+ if (ldns_dnssec_trust_tree_add_parent(new_tree,
+ cur_parent_tree, cur_sig_rr, cur_status))
+ ldns_dnssec_trust_tree_free(cur_parent_tree);
}
}
}
data_chain->parent,
cur_parent_rr,
check_time);
- (void) ldns_dnssec_trust_tree_add_parent(new_tree,
- cur_parent_tree, NULL, result);
+ if (ldns_dnssec_trust_tree_add_parent(new_tree,
+ cur_parent_tree, NULL, result))
+ ldns_dnssec_trust_tree_free(cur_parent_tree);
+
}
}
}
ldns_pkt_free(p);
p = NULL;
- status = ldns_resolver_send(&p, res, name, t, c, 0);
+ (void) ldns_resolver_send(&p, res, name, t, c, 0);
if (!p) {
goto cleanup;
}
#ifdef HAVE_SSL
if (strchr(optarg, ':')) {
tsig_separator = (size_t) (strchr(optarg, ':') - optarg);
+ if (tsig_algorithm) {
+ free(tsig_algorithm);
+ tsig_algorithm = NULL;
+ }
if (strchr(optarg + tsig_separator + 1, ':')) {
tsig_separator2 = (size_t) (strchr(optarg + tsig_separator + 1, ':') - optarg);
tsig_algorithm = xmalloc(strlen(optarg) - tsig_separator2);
goto done;
}
}
- labels = LDNS_XMALLOC(ldns_rdf*, labels_count + 2);
+ labels = LDNS_CALLOC(ldns_rdf*, labels_count + 2);
if (!labels) {
goto done;
}
*/
for(i = (ssize_t)labels_count + 1; i > 0; i--) {
status = ldns_resolver_send(&local_p, res, labels[i], LDNS_RR_TYPE_NS, c, 0);
+ if (status != LDNS_STATUS_OK) {
+ fprintf(stderr, "Error sending query: %s\n", ldns_get_errorstr_by_id(status));
+ result = status;
+ goto done;
+ }
+
+ /* TODO: handle status */
if (verbosity >= 5) {
ldns_pkt_print(stdout, local_p);
return NULL;
} else {
duration->weeks = (time_t) atoi(str+1);
- str = W;
}
}
return duration;
argv += optind;
if (argc != 2) {
- argc -= optind;
argv -= optind;
usage(argv[0]);
exit(EXIT_FAILURE);
match_expression *expr;
size_t i,j;
size_t leftstart, leftend = 0;
- char *left_str, *op, *val;
+ char *left_str, *op = NULL, *val;
match_table *mt;
match_operation *mo = NULL;
const type_operators *tos;
ldns_lookup_table *lt = NULL;
/* remove whitespace */
- char *str = malloc(strlen(string) + 1);
+ char *str = calloc(1, strlen(string) + 1);
j = 0;
for (i = 0; i < strlen(string); i++) {
if (i > strlen(str)) {
printf("parse error no right hand side: %s\n", str);
result = NULL;
+ if (op)
+ free(op);
goto done;
}
}
mt = get_match_by_name(left_str);
if (!mt) {
printf("parse error: unknown match name: %s\n", left_str);
+ if (op)
+ free(op);
result = NULL;
goto done;
} else {
tos = get_type_operators(mt->type);
for (j = 0; j < tos->operator_count; j++) {
if (get_op_id(op) == tos->operators[j]) {
+ if (mo)
+ free(mo);
mo = malloc(sizeof(match_operation));
mo->id = mt->id;
mo->operator = get_op_id(op);
if (!mo) {
printf("parse error: operator %s not allowed for match %s\n", op, left_str);
result = NULL;
+ if (op)
+ free(op);
goto done;
}
}
int ip_hdr_size;
uint8_t protocol;
size_t data_offset = 0;
- ldns_rdf *src_addr, *dst_addr;
+ ldns_rdf *src_addr = NULL, *dst_addr = NULL;
uint8_t *ap;
char *astr;
bpf_u_int32 len = cur_hdr.caplen;
ldns_pkt_free(pkt);
ldns_rdf_deep_free(src_addr);
ldns_rdf_deep_free(dst_addr);
+ if (newdata && newdata != data)
+ free((void *)newdata);
return 0;
}
} else {
/* tcp packets are skipped */
tcp_packets++;
}
+ if (newdata && newdata != data) {
+ free((void *)newdata);
+ newdata = NULL;
+ }
/* don't have a define for ethertype ipv6 */
} else if (ntohs (eptr->ether_type) == ETHERTYPE_IPV6) {
/*printf("IPv6!\n");*/
if (ldns_str2rdf_aaaa(&src_addr, astr) == LDNS_STATUS_OK) {
}
- free(astr);
}
+ free(astr);
ap = (uint8_t *) &(ip6_hdr->ip6_dst);
astr = malloc(INET6_ADDRSTRLEN);
if (inet_ntop(AF_INET6, ap, astr, INET6_ADDRSTRLEN)) {
if (ldns_str2rdf_aaaa(&dst_addr, astr) == LDNS_STATUS_OK) {
}
- free(astr);
}
+ free(astr);
ip_hdr_size = IP6_HEADER_LENGTH;
protocol = (uint8_t) ip6_hdr->ip6_ctlun.ip6_un1.ip6_un1_nxt;
match_table *mt;
/*printf("Parsing unique counts: '%s'\n", string);*/
- str = malloc(strlen(string) + 1);
+ str = calloc(1, strlen(string) + 1);
j = 0;
for (i = 0; i < strlen(string); i++) {
if (!isspace((unsigned char)string[i])) {
lastpos = 0;
for (i = 0; i <= strlen(str); i++) {
if (str[i] == ',' || i >= strlen(str)) {
- strpart = malloc(i - lastpos + 1);
+ if (!(strpart = malloc(i - lastpos + 1))) {
+ free(str);
+ return false;
+ }
strncpy(strpart, &str[lastpos], i - lastpos);
strpart[i - lastpos] = '\0';
if ((mt = get_match_by_name(strpart))) {
*count = *count + 1;
} else {
printf("Error parsing match list; unknown match name: %s\n", strpart);
+ free(strpart);
free(str);
return false;
}
return false;
}
free(strpart);
- lastpos = i + 1;
}
free(str);
return true;
ldns_status result = LDNS_STATUS_OK;
int sep_only = 1;
- alg = 0;
h = LDNS_SHA1;
argv++, argc--;
if (!p) {
fprintf(stderr, "no packet received\n");
+ LDNS_FREE(last_nameservers);
return NULL;
}
fprintf(stderr, "Error: nameserver at ");
ldns_rdf_print(stderr, last_nameservers[nss_i]);
fprintf(stderr, " not responding. Unable to check RRset here, aborting.\n");
+ LDNS_FREE(last_nameservers);
return NULL;
}
if (ldns_pkt_get_rcode(p) != LDNS_RCODE_NOERROR) {
printf("Error in packet:\n");
ldns_pkt_print(stdout, p);
+ LDNS_FREE(last_nameservers);
return NULL;
}
}
status = ldns_pkt2wire(&wire, notify, &wiresize);
- if(wiresize == 0) {
+ if (status) {
+ printf("Error converting notify packet to hex: %s\n",
+ ldns_get_errorstr_by_id(status));
+ } else if(wiresize == 0) {
printf("Error converting notify packet to hex.\n");
exit(1);
}
-
if(do_hexdump && verbose > 1) {
printf("Hexdump of notify packet:\n");
for(i=0; i<(int)wiresize; i++)
fprintf(stderr, "Salt too long\n");
exit(EXIT_FAILURE);
}
+ if (nsec3_salt) LDNS_FREE(nsec3_salt);
nsec3_salt_length = (uint8_t) (strlen(optarg) / 2);
nsec3_salt = LDNS_XMALLOC(uint8_t, nsec3_salt_length);
for (c = 0; c < (int) strlen(optarg); c += 2) {
} else {
dname = ldns_dname_new_frm_str(argv[0]);
if (!dname) {
+ free(prog);
+ if (nsec3_salt) free(nsec3_salt);
fprintf(stderr,
"Error: unable to parse domain name\n");
return EXIT_FAILURE;
nsec3_salt_length,
nsec3_salt);
if (!hashed_dname) {
+ free(prog);
+ if (nsec3_salt) free(nsec3_salt);
fprintf(stderr,
"Error creating NSEC3 hash\n");
return EXIT_FAILURE;
if (argc == 3) {
/* optional type arg */
- type_name = strdup(argv[2]);
+ type_name = argv[2];
t = ldns_rdf2rr_type(
ldns_rdf_new_frm_str(LDNS_RDF_TYPE_TYPE, type_name));
if (t == 0) {
struct sockaddr_storage addr_him;
socklen_t hislen;
uint8_t inbuf[INBUF_SIZE];
- uint16_t tcplen;
+ uint16_t tcplen = 0;
struct handle_tcp_userdata userdata;
/* accept */
void verbose(int lvl, const char* msg, ...) ATTR_FORMAT(printf, 2, 3);
/** print error and exit */
+static void error(const char* msg, ...) __attribute__((noreturn));
static void error(const char* msg, ...)
{
va_list args;
return label;
}
-static ldns_status
+static void
query_type_bitmaps(ldns_resolver *res,
uint16_t res_flags,
const ldns_rdf *name,
}
}
}
-
pos += (uint16_t) bitmap_length;
}
-
- return LDNS_STATUS_OK;
}
/* ok, so now we know all the types present at this name,
* query for those one by one (...)
*/
- status = query_type_bitmaps(res, LDNS_RD, ldns_rr_owner(nsec_rr),
+ query_type_bitmaps(res, LDNS_RD, ldns_rr_owner(nsec_rr),
ldns_rr_rdf(nsec_rr, 1));
/* print this nsec and its signatures too */
ldns_rr_print(stdout, nsec_rr);
if (status != LDNS_STATUS_OK) {
printf("Error creating answer: %s\n", ldns_get_errorstr_by_id(status));
} else {
- nb = sendto(sock, (void*)outbuf, answer_size, 0,
+ (void) sendto(sock, (void*)outbuf, answer_size, 0,
&addr_him, hislen);
}
ldns_status
ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf)
{
- size_t size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf));
+ size_t size;
char *b64;
if (ldns_rdf_size(rdf) == 0) {
ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
status=ldns_algorithm2buffer_str(output, (ldns_algorithm)ldns_key_algorithm(k));
ldns_buffer_printf(output, ")\n");
+ if (status) break;
status = ldns_ed25519_key2buffer_str(output,
k->_key.key);
break;
ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
status=ldns_algorithm2buffer_str(output, (ldns_algorithm)ldns_key_algorithm(k));
ldns_buffer_printf(output, ")\n");
+ if (status) break;
status = ldns_ed448_key2buffer_str(output,
k->_key.key);
break;
return LDNS_STATUS_NETWORK_ERR;
}
- /* resize accordingly */
- *result = LDNS_XREALLOC(answer, uint8_t, (size_t)*answer_size);
- if(!*result) {
- LDNS_FREE(answer);
- return LDNS_STATUS_MEM_ERR;
- }
+ *result = answer;
return LDNS_STATUS_OK;
}
status = ldns_wire2pkt(&reply, reply_bytes, reply_size);
if (status != LDNS_STATUS_OK) {
+ if(src) LDNS_FREE(src);
LDNS_FREE(reply_bytes);
LDNS_FREE(ns);
return status;
}
+ assert(reply);
LDNS_FREE(ns);
gettimeofday(&tv_e, NULL);
ldns_status
ldns_resolver_new_frm_fp_l(ldns_resolver **res, FILE *fp, int *line_nr)
{
- ldns_resolver *r;
+ ldns_resolver *r = NULL;
const char *keyword[LDNS_RESOLV_KEYWORDS];
char word[LDNS_MAX_LINELEN + 1];
int8_t expect;
keyword[LDNS_RESOLV_SORTLIST] = "sortlist";
keyword[LDNS_RESOLV_OPTIONS] = "options";
keyword[LDNS_RESOLV_ANCHOR] = "anchor";
- expect = LDNS_RESOLV_KEYWORD;
r = ldns_resolver_new();
if (!r) {
gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
if (gtr == 0) {
if(!fp) fclose(myfp);
+ ldns_resolver_deep_free(r);
return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
}
if(word[0] == '#') {
}
tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, word);
if (!tmp) {
- ldns_resolver_deep_free(r);
if(!fp) fclose(myfp);
+ ldns_resolver_deep_free(r);
return LDNS_STATUS_SYNTAX_DNAME_ERR;
}
gtr = ldns_fget_token_l(myfp, word, LDNS_PARSE_NORMAL, 0, line_nr);
if (gtr == 0) {
if(!fp) fclose(myfp);
+ ldns_resolver_deep_free(r);
return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
}
if(word[0] == '#') {
rd_buf, rd, delimiters, LDNS_MAX_RDFLEN))) {
done = true;
+ (void)done; /* we're breaking, so done not read anymore */
break;
}
/* hmmz, rfc3597 specifies that any type can be represented
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
+ (void)a;
}
/* Clean up */
a = b = c = d = e = f = g = h = T1 = T2 = 0;
+ (void)a;
}
#endif /* SHA2_UNROLL_TRANSFORM */
context->bitcount += len << 3;
/* Clean up: */
usedspace = freespace = 0;
+ (void)usedspace;
return;
}
}
}
/* Clean up: */
usedspace = freespace = 0;
+ (void)usedspace;
}
typedef union _ldns_sha2_buffer_union {
/* Clean up state data: */
MEMSET_BZERO(context, sizeof(ldns_sha256_CTX));
usedspace = 0;
+ (void)usedspace;
}
unsigned char *
/* Clean up */
a = b = c = d = e = f = g = h = T1 = T2 = 0;
+ (void)a;
}
#endif /* SHA2_UNROLL_TRANSFORM */
ADDINC128(context->bitcount, len << 3);
/* Clean up: */
usedspace = freespace = 0;
+ (void)usedspace;
return;
}
}
}
/* Clean up: */
usedspace = freespace = 0;
+ (void)usedspace;
}
static void ldns_sha512_Last(ldns_sha512_CTX* context) {
ldns_str2rdf_time(ldns_rdf **rd, const char *time)
{
/* convert a time YYYYDDMMHHMMSS to wireformat */
- uint16_t *r = NULL;
+ uint32_t *r = NULL;
struct tm tm;
uint32_t l;
char *end;
/* Try to scan the time... */
- r = (uint16_t*)LDNS_MALLOC(uint32_t);
+ r = (uint32_t *)LDNS_MALLOC(uint32_t);
if(!r) return LDNS_STATUS_MEM_ERR;
memset(&tm, 0, sizeof(tm));
ldns_str2rdf_int32(ldns_rdf **rd, const char *longstr)
{
char *end;
- uint16_t *r = NULL;
+ uint32_t *r = NULL;
uint32_t l;
- r = (uint16_t*)LDNS_MALLOC(uint32_t);
+ r = (uint32_t*)LDNS_MALLOC(uint32_t);
if(!r) return LDNS_STATUS_MEM_ERR;
errno = 0; /* must set to zero before call,
note race condition on errno */
size_t rdf_size = 4 + hit_wire_size + pk_wire_size;
char *endptr; /* utility var for strtol usage */
- int algorithm = strtol(str, &endptr, 10);
+ int algorithm = str == NULL ? 0 : strtol(str, &endptr, 10);
uint8_t *data, *dp;
int hi, lo, written;