Commit f93b35e1 authored by Daniel Salzman's avatar Daniel Salzman

dname: change int to size_t return type where reasonable

parent 398cef3c
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -159,7 +159,7 @@ conf_val_t conf_zone_get_txn(
return val;
}
int dname_size = knot_dname_size(dname);
size_t dname_size = knot_dname_size(dname);
// Try to get explicit value.
conf_db_get(conf, txn, C_ZONE, key1_name, dname, dname_size, &val);
......@@ -888,9 +888,9 @@ static int str_label(
const knot_dname_t *zone,
char *buff,
size_t buff_len,
unsigned right_index)
size_t right_index)
{
int labels = knot_dname_labels(zone, NULL);
size_t labels = knot_dname_labels(zone, NULL);
// Check for root label of the root zone.
if (labels == 0 && right_index == 0) {
......@@ -906,12 +906,12 @@ static int str_label(
// Compute the index from the left.
assert(labels > right_index);
unsigned index = labels - right_index - 1;
size_t index = labels - right_index - 1;
// Create a dname from the single label.
int prefix = (index > 0) ? knot_dname_prefixlen(zone, index, NULL) : 0;
unsigned label_len = *(zone + prefix);
memcpy(label, zone + prefix, 1 + label_len);
size_t prefix_len = knot_dname_prefixlen(zone, index, NULL);
size_t label_len = *(zone + prefix_len);
memcpy(label, zone + prefix_len, 1 + label_len);
label[1 + label_len] = '\0';
return str_zone(label, buff, buff_len);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -579,7 +579,7 @@ static int get_owner(uint8_t *out, size_t out_len, knot_dname_t *origin,
assert(owner != NULL);
bool fqdn = false;
int prefix_len = 0;
size_t prefix_len = 0;
size_t owner_len = strlen(owner);
if (owner_len > 0 && (owner_len != 1 || owner[0] != '@')) {
......@@ -599,7 +599,7 @@ static int get_owner(uint8_t *out, size_t out_len, knot_dname_t *origin,
}
prefix_len = knot_dname_size(out);
if (prefix_len <= 0) {
if (prefix_len == 0) {
return KNOT_EINVAL;
}
......@@ -609,8 +609,8 @@ static int get_owner(uint8_t *out, size_t out_len, knot_dname_t *origin,
// Append the origin.
if (!fqdn) {
int origin_len = knot_dname_size(origin);
if (origin_len <= 0 || origin_len > out_len - prefix_len) {
size_t origin_len = knot_dname_size(origin);
if (origin_len == 0 || origin_len > out_len - prefix_len) {
return KNOT_EINVAL;
}
memcpy(out + prefix_len, origin, origin_len);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -170,7 +170,7 @@ void kasp_db_close(kasp_db_t **db)
static knot_db_val_t make_key(keyclass_t kclass, const knot_dname_t *dname, const char *str)
{
size_t dnlen = (dname == NULL ? 0 : knot_dname_size((const knot_dname_t *)dname));
size_t dnlen = knot_dname_size(dname);
size_t slen = (str == NULL ? 0 : strlen(str) + 1);
knot_db_val_t res = { .len = 1 + dnlen + slen, .data = malloc(1 + dnlen + slen) };
if (res.data != NULL) {
......@@ -195,7 +195,7 @@ static char *keyid_fromkey(const knot_db_val_t *key)
if (key->len < 2 || *(uint8_t *)key->data != KASPDBKEY_PARAMS) {
return NULL;
}
size_t skip = knot_dname_size((const knot_dname_t *)key->data + 1);
size_t skip = knot_dname_size((const uint8_t *)key->data + 1);
return (key->len < skip + 2 ? NULL : strdup(key->data + skip + 1));
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -52,9 +52,7 @@ static size_t rrsig_rdata_header_size(const dnssec_key_t *key)
// variable part
const uint8_t *signer = dnssec_key_get_dname(key);
assert(signer);
size += knot_dname_size(signer);
size += knot_dname_size(dnssec_key_get_dname(key));
return size;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -152,14 +152,9 @@ int knot_create_nsec3_owner(uint8_t *out, size_t out_size,
return KNOT_EINVAL;
}
int owner_size = knot_dname_size(owner);
if (owner_size < 0) {
return KNOT_EINVAL;
}
dnssec_binary_t data = {
.data = (uint8_t *)owner,
.size = owner_size
.size = knot_dname_size(owner)
};
dnssec_binary_t hash = { 0 };
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -170,8 +170,7 @@ static void txn_init(txn_t *txn, knot_db_txn_t *db_txn, journal_t *j)
static void txn_key_str(txn_t *txn, const knot_dname_t *zone, const char *key)
{
size_t zone_size = 0;
if (zone != NULL) zone_size = knot_dname_size(zone);
size_t zone_size = knot_dname_size(zone);
txn->key.len = zone_size + DB_KEY_UNUSED_ZERO + strlen(key) + 1;
if (txn->key.len > 512) {
txn->ret = KNOT_ERROR;
......@@ -184,8 +183,7 @@ static void txn_key_str(txn_t *txn, const knot_dname_t *zone, const char *key)
static void txn_key_2u32(txn_t *txn, const knot_dname_t *zone, uint32_t key1, uint32_t key2)
{
size_t zone_size = 0;
if (zone != NULL) zone_size = knot_dname_size(zone);
size_t zone_size = knot_dname_size(zone);
txn->key.len = zone_size + DB_KEY_UNUSED_ZERO + 2*sizeof(uint32_t);
if (txn->key.len > 512) {
txn->ret = KNOT_ERROR;
......@@ -202,8 +200,7 @@ static void txn_key_2u32(txn_t *txn, const knot_dname_t *zone, uint32_t key1, ui
static void txn_key_str_u32(txn_t *txn, const knot_dname_t *zone, const char *key1, uint32_t key2)
{
size_t zone_size = 0;
if (zone != NULL) zone_size = knot_dname_size(zone);
size_t zone_size = knot_dname_size(zone);
txn->key.len = zone_size + DB_KEY_UNUSED_ZERO + strlen(key1) + 1 + sizeof(uint32_t);
if (txn->key.len > 512) {
txn->ret = KNOT_ERROR;
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -66,10 +66,7 @@ static int deserialize_rrset(wire_ctx_t *wire, knot_rrset_t *rrset, long *phase)
if (*phase == SERIALIZE_RRSET_INIT && wire_ctx_available(wire) > 0) {
// Read owner, rtype, rclass and RR count.
int size = knot_dname_size(wire->position);
if (size < 0) {
return size;
}
size_t size = knot_dname_size(wire->position);
knot_dname_t *owner = knot_dname_copy_part(wire->position, size, NULL);
if (owner == NULL || wire_ctx_available(wire) < size + 3 * sizeof(uint16_t)) {
return KNOT_EMALF;
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -78,8 +78,8 @@ knot_dname_t *online_nsec_next(const knot_dname_t *dname, const knot_dname_t *ap
// right aligned copy of the domain name
uint8_t copy[KNOT_DNAME_MAXLEN] = { 0 };
int dname_len = knot_dname_size(dname);
int empty_len = sizeof(copy) - dname_len;
size_t dname_len = knot_dname_size(dname);
size_t empty_len = sizeof(copy) - dname_len;
uint8_t *pos = copy + empty_len;
memmove(pos, dname, dname_len);
......@@ -92,7 +92,7 @@ knot_dname_t *online_nsec_next(const knot_dname_t *dname, const knot_dname_t *ap
}
// find apex position in the buffer
int apex_len = knot_dname_size(apex);
size_t apex_len = knot_dname_size(apex);
const uint8_t *apex_pos = copy + sizeof(copy) - apex_len;
assert(knot_dname_cmp(apex, apex_pos) == 0);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -73,7 +73,7 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
/* Replace last labels of qname with DNAME. */
const knot_dname_t *dname_wire = dname_rr->owner;
const knot_dname_t *dname_tgt = knot_dname_target(&dname_rr->rrs);
int labels = knot_dname_labels(dname_wire, NULL);
size_t labels = knot_dname_labels(dname_wire, NULL);
knot_dname_t *cname = knot_dname_replace_suffix(qname, labels, dname_tgt);
if (cname == NULL) {
knot_dname_free(&owner_copy, mm);
......@@ -81,7 +81,7 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
}
/* Store DNAME into RDATA. */
int cname_size = knot_dname_size(cname);
size_t cname_size = knot_dname_size(cname);
uint8_t cname_rdata[cname_size];
memcpy(cname_rdata, cname, cname_size);
knot_dname_free(&cname, NULL);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -117,8 +117,8 @@ static const zone_node_t *nsec3_encloser(const zone_node_t *closest)
static const knot_dname_t *get_next_closer(const knot_dname_t *closest_encloser,
const knot_dname_t *name)
{
int ce_labels = knot_dname_labels(closest_encloser, NULL);
int qname_labels = knot_dname_labels(name, NULL);
size_t ce_labels = knot_dname_labels(closest_encloser, NULL);
size_t qname_labels = knot_dname_labels(name, NULL);
// the common labels should match
assert(knot_dname_matched_labels(closest_encloser, name) == ce_labels);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -818,7 +818,7 @@ int zone_contents_find_dname(const zone_contents_t *zone,
assert(!node && prev);
node = prev;
int matched_labels = knot_dname_matched_labels(node->owner, name);
size_t matched_labels = knot_dname_matched_labels(node->owner, name);
while (matched_labels < knot_dname_labels(node->owner, NULL)) {
node = node->parent;
assert(node);
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -306,13 +306,13 @@ static int check_rrsig_rdata(sem_handler_t *handler,
/* label number at the 2nd index should be same as owner's */
uint8_t labels_rdata = knot_rrsig_labels(rrsig, rr_pos);
int tmp = knot_dname_labels(rrset->owner, NULL) - labels_rdata;
size_t tmp = knot_dname_labels(rrset->owner, NULL) - labels_rdata;
if (tmp != 0) {
/* if name has wildcard, label must not be included */
if (!knot_dname_is_wildcard(rrset->owner)) {
handler->cb(handler, zone, node, SEM_ERR_RRSIG_RDATA_LABELS,
info_str);
} else if (abs(tmp) != 1) {
} else if (tmp != 1) {
handler->cb(handler, zone, node, SEM_ERR_RRSIG_RDATA_LABELS,
info_str);
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -107,8 +107,8 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos,
}
/* Calculate decompressed length. */
int decompressed_len = knot_dname_realsize(name, pkt);
if (decompressed_len < 1) {
size_t decompressed_len = knot_dname_realsize(name, pkt);
if (decompressed_len == 0) {
return NULL;
}
......@@ -159,7 +159,7 @@ int knot_dname_to_wire(uint8_t *dst, const knot_dname_t *src, size_t maxlen)
return KNOT_EINVAL;
}
int len = knot_dname_size(src);
size_t len = knot_dname_size(src);
if (len > maxlen) {
return KNOT_ESPACE;
}
......@@ -204,10 +204,7 @@ char *knot_dname_to_str(char *dst, const knot_dname_t *name, size_t maxlen)
return NULL;
}
int dname_size = knot_dname_size(name);
if (dname_size <= 0) {
return NULL;
}
size_t dname_size = knot_dname_size(name);
/* Check the size for len(dname) + 1 char termination. */
size_t alloc_size = (dst == NULL) ? dname_size + 1 : maxlen;
......@@ -464,53 +461,62 @@ int knot_dname_to_lower(knot_dname_t *name)
}
_public_
int knot_dname_size(const knot_dname_t *name)
size_t knot_dname_size(const knot_dname_t *name)
{
if (name == NULL)
return KNOT_EINVAL;
if (name == NULL) {
return 0;
}
/* Count name size without terminal label. */
int len = 0;
size_t len = 0;
while (*name != '\0' && !knot_wire_is_pointer(name)) {
uint8_t lblen = *name + 1;
len += lblen;
name += lblen;
}
/* Compression pointer is 2 octets. */
if (knot_wire_is_pointer(name))
if (knot_wire_is_pointer(name)) {
/* Add 2-octet compression pointer. */
return len + 2;
return len + 1;
} else {
/* Add 1-octet terminal label. */
return len + 1;
}
}
_public_
int knot_dname_realsize(const knot_dname_t *name, const uint8_t *pkt)
size_t knot_dname_realsize(const knot_dname_t *name, const uint8_t *pkt)
{
/* Add zero label size for FQDN. */
return knot_dname_prefixlen(name, KNOT_DNAME_MAXLABELS, pkt) + 1;
if (name == NULL) {
return 0;
}
/* Seek first real label occurrence. */
name = knot_wire_seek_label(name, pkt);
size_t len = 0;
while (*name != '\0') {
len += *name + 1;
name = knot_wire_next_label(name, pkt);
}
/* Add 1-octet terminal label. */
return len + 1;
}
_public_
bool knot_dname_is_sub(const knot_dname_t *sub, const knot_dname_t *domain)
{
if (sub == domain)
return false;
/* Count labels. */
assert(sub != NULL && domain != NULL);
int sub_l = knot_dname_labels(sub, NULL);
int domain_l = knot_dname_labels(domain, NULL);
if (sub_l < 0 || domain_l < 0)
if (sub == NULL || domain == NULL || sub == domain) {
return false;
}
assert(sub_l >= 0 && sub_l <= KNOT_DNAME_MAXLABELS);
assert(domain_l >= 0 && domain_l <= KNOT_DNAME_MAXLABELS);
/* Subdomain must have more labels as parent. */
if (sub_l <= domain_l)
/* Subdomain must have more labels than parent. */
size_t sub_l = knot_dname_labels(sub, NULL);
size_t domain_l = knot_dname_labels(domain, NULL);
if (sub_l <= domain_l) {
return false;
}
/* Align end-to-end to common suffix. */
int common = knot_dname_align(&sub, sub_l, &domain, domain_l, NULL);
......@@ -518,8 +524,9 @@ bool knot_dname_is_sub(const knot_dname_t *sub, const knot_dname_t *domain)
/* Compare common suffix. */
while (common > 0) {
/* Compare label. */
if (!label_is_equal(sub, domain))
if (!label_is_equal(sub, domain)) {
return false;
}
/* Next label. */
sub = knot_wire_next_label(sub, NULL);
domain = knot_wire_next_label(domain, NULL);
......@@ -537,36 +544,34 @@ bool knot_dname_in(const knot_dname_t *domain, const knot_dname_t *sub)
_public_
bool knot_dname_is_wildcard(const knot_dname_t *name)
{
assert(name != NULL);
if (name == NULL) {
return false;
}
return name[0] == 1 && name[1] == '*';
}
_public_
int knot_dname_matched_labels(const knot_dname_t *d1, const knot_dname_t *d2)
size_t knot_dname_matched_labels(const knot_dname_t *d1, const knot_dname_t *d2)
{
if (d1 == NULL || d2 == NULL)
return KNOT_EINVAL;
/* Count labels. */
int l1 = knot_dname_labels(d1, NULL);
int l2 = knot_dname_labels(d2, NULL);
if (l1 < 0 || l2 < 0)
return KNOT_EINVAL;
assert(l1 >= 0 && l1 <= KNOT_DNAME_MAXLABELS);
assert(l2 >= 0 && l2 <= KNOT_DNAME_MAXLABELS);
size_t l1 = knot_dname_labels(d1, NULL);
size_t l2 = knot_dname_labels(d2, NULL);
if (l1 == 0 || l2 == 0) {
return 0;
}
/* Align end-to-end to common suffix. */
int common = knot_dname_align(&d1, l1, &d2, l2, NULL);
/* Count longest chain leading to root label. */
int matched = 0;
size_t matched = 0;
while (common > 0) {
if (label_is_equal(d1, d2))
if (label_is_equal(d1, d2)) {
++matched;
else
} else {
matched = 0; /* Broken chain. */
}
/* Next label. */
d1 = knot_wire_next_label(d1, NULL);
......@@ -581,24 +586,29 @@ _public_
knot_dname_t *knot_dname_replace_suffix(const knot_dname_t *name, unsigned labels,
const knot_dname_t *suffix)
{
if (name == NULL)
if (name == NULL) {
return NULL;
}
/* Calculate prefix and suffix lengths. */
int dname_lbs = knot_dname_labels(name, NULL);
assert(dname_lbs >= labels);
unsigned prefix_lbs = dname_lbs - labels;
size_t dname_lbs = knot_dname_labels(name, NULL);
if (dname_lbs < labels) {
return NULL;
}
size_t prefix_lbs = dname_lbs - labels;
int prefix_len = knot_dname_prefixlen(name, prefix_lbs, NULL);
int suffix_len = knot_dname_size(suffix);
if (prefix_len < 0 || suffix_len < 0)
size_t prefix_len = knot_dname_prefixlen(name, prefix_lbs, NULL);
size_t suffix_len = knot_dname_size(suffix);
if (prefix_len == 0 || suffix_len == 0) {
return NULL;
}
/* Create target name. */
int new_len = prefix_len + suffix_len;
size_t new_len = prefix_len + suffix_len;
knot_dname_t *out = malloc(new_len);
if (out == NULL)
if (out == NULL) {
return NULL;
}
/* Copy prefix. */
uint8_t *dst = out;
......@@ -718,41 +728,46 @@ knot_dname_t *knot_dname_cat(knot_dname_t *d1, const knot_dname_t *d2)
}
_public_
int knot_dname_prefixlen(const uint8_t *name, unsigned nlabels, const uint8_t *pkt)
size_t knot_dname_prefixlen(const uint8_t *name, unsigned nlabels, const uint8_t *pkt)
{
if (name == NULL)
return KNOT_EINVAL;
if (name == NULL) {
return 0;
}
/* Zero labels means no prefix. */
if (nlabels == 0)
if (nlabels == 0) {
return 0;
}
/* Seek first real label occurrence. */
name = knot_wire_seek_label(name, pkt);
int len = 0;
size_t len = 0;
while (*name != '\0') {
len += *name + 1;
name = knot_wire_next_label(name, pkt);
if (--nlabels == 0) /* Count N first labels only. */
if (--nlabels == 0) { /* Count N first labels only. */
break;
}
}
return len;
}
_public_
int knot_dname_labels(const uint8_t *name, const uint8_t *pkt)
size_t knot_dname_labels(const uint8_t *name, const uint8_t *pkt)
{
if (name == NULL)
return KNOT_EINVAL;
if (name == NULL) {
return 0;
}
uint8_t count = 0;
size_t count = 0;
while (*name != '\0') {
++count;
name = knot_wire_next_label((uint8_t *)name, (uint8_t *)pkt);
if (!name)
return KNOT_EMALF;
name = knot_wire_next_label(name, pkt);
if (name == NULL) {
return 0;
}
}
return count;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -188,22 +188,22 @@ int knot_dname_to_lower(knot_dname_t *name);
* \param name Domain name to get the size of.
*
* \retval size of the domain name.
* \retval KNOT_EINVAL
* \retval 0 if invalid argument.
*/
_pure_
int knot_dname_size(const knot_dname_t *name);
size_t knot_dname_size(const knot_dname_t *name);
/*!
* \brief Returns wire size of the given domain name (expanded compression ptrs).
* \brief Returns full size of the given domain name (expanded compression ptrs).
*
* \param name Domain name to get the size of.
* \param pkt Related packet (or NULL if unpacked)
*
* \retval size of the domain name.
* \retval KNOT_EINVAL
* \retval 0 if invalid argument.
*/
_pure_
int knot_dname_realsize(const knot_dname_t *name, const uint8_t *pkt);
size_t knot_dname_realsize(const knot_dname_t *name, const uint8_t *pkt);
/*!
* \brief Checks if one domain name is a subdomain of other.
......@@ -250,7 +250,7 @@ bool knot_dname_is_wildcard(const knot_dname_t *name);
* \return Number of labels common for the two domain names.
*/
_pure_
int knot_dname_matched_labels(const knot_dname_t *d1, const knot_dname_t *d2);
size_t knot_dname_matched_labels(const knot_dname_t *d1, const knot_dname_t *d2);
/*!
* \brief Replaces the suffix of given size in one domain name with other domain
......@@ -343,10 +343,10 @@ knot_dname_t *knot_dname_cat(knot_dname_t *d1, const knot_dname_t *d2);
* \param nlabels N first labels.
* \param pkt Related packet (or NULL if not compressed).
*
* \retval length of the prefix
* \return Length of the prefix.
*/
_pure_
int knot_dname_prefixlen(const uint8_t *name, unsigned nlabels, const uint8_t *pkt);
size_t knot_dname_prefixlen(const uint8_t *name, unsigned nlabels, const uint8_t *pkt);
/*!
* \brief Return number of labels in the domain name.
......@@ -355,9 +355,11 @@ int knot_dname_prefixlen(const uint8_t *name, unsigned nlabels, const uint8_t *p
*
* \param name Domain name.
* \param pkt Related packet (or NULL if not compressed).
*
* \return Number of labels.
*/
_pure_
int knot_dname_labels(const uint8_t *name, const uint8_t *pkt);
size_t knot_dname_labels(const uint8_t *name, const uint8_t *pkt);
/*!
* \brief Align name end-to-end and return number of common suffix labels.
......@@ -385,7 +387,7 @@ int knot_dname_align(const uint8_t **d1, uint8_t d1_labels,
*
* Maximum length of such a domain name is KNOT_DNAME_MAXLEN characters.
*
* \param dst Memory to store converted name into. dst[0] will contain the length.
* \param dst Memory to store converted name into. dst[0] will contain the length.
* \param src Source domain name.
* \param pkt Source name packet (NULL if not any).
*
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -45,7 +45,7 @@ int knot_compr_put_dname(const knot_dname_t *dname, uint8_t *dst, uint16_t max,
}
/* Get number of labels (should not be a zero label dname). */
int name_labels = knot_dname_labels(dname, NULL);
size_t name_labels = knot_dname_labels(dname, NULL);
assert(name_labels > 0);
/* Suffix must not be longer than whole name. */
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -226,18 +226,11 @@ static int rdata_len_block(const uint8_t **src, size_t *src_avail,
case KNOT_RDATA_WF_FIXED_DNAME:
compr_size = knot_dname_wire_check(*src, *src + *src_avail,
pkt_wire);
if (compr_size < 0) {
return compr_size;
}
if (compr_size == 0) {
if (compr_size <= 0) {
return KNOT_EMALF;
}
ret = knot_dname_realsize(*src, pkt_wire);
if (ret < 0) {
return ret;
}
*src += compr_size;
*src_avail -= compr_size;
break;
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -817,12 +817,7 @@ static void wire_dname_to_str(rrset_dump_params_t *p)
{
CHECK_PRET
int in_len = knot_dname_size(p->in);
if (in_len < 0) {
p->ret = -1;
return;
}
size_t in_len = knot_dname_size(p->in);
size_t out_len = 0;
CHECK_INMAX(in_len)
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -222,11 +222,7 @@ int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
if (ret != KNOT_EOK) {
return ret;
}
ret = knot_dname_size(pos);
if (ret < 0) {
return ret;
}
pos += ret;
break;
......@@ -259,7 +255,6 @@ size_t knot_rrset_size(const knot_rrset_t *rrset)
uint16_t rr_count = rrset->rrs.rr_count;
assert(rrset->owner);