Commit 31e3c38b authored by Daniel Salzman's avatar Daniel Salzman

libknot/dname: revise letter-case comparison

parent 81b741e3
......@@ -204,7 +204,7 @@ static bool check_key_zone(const knot_db_val_t *key, const knot_dname_t *zone_na
if (key->len < 2 || *(uint8_t *)key->data == KASPDBKEY_POLICYLAST) {
return false;
}
return (knot_dname_cmp(key->data + 1, zone_name) == 0);
return knot_dname_is_equal(key->data + 1, zone_name);
}
static int serialize_key_params(const key_params_t *params, const knot_dname_t *dname, knot_db_val_t *key, knot_db_val_t *val)
......@@ -722,7 +722,7 @@ int kasp_db_list_zones(kasp_db_t *db, list_t *dst)
ptrnode_t *n;
WALK_LIST(n, *dst) {
knot_dname_t *exist_dn = (knot_dname_t *)n->d;
if (knot_dname_cmp(key_dn, exist_dn) == 0) {
if (knot_dname_is_equal(key_dn, exist_dn)) {
key_dn = NULL;
break;
}
......
......@@ -98,7 +98,7 @@ knot_dname_t *online_nsec_next(const knot_dname_t *dname, const knot_dname_t *ap
// find apex position in the buffer
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);
assert(knot_dname_is_equal(apex, apex_pos));
// find first label which can be incremented
while (pos != apex_pos) {
......
/* Copyright (C) 2016 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
......@@ -39,9 +39,9 @@ bool acl_allowed(conf_t *conf, conf_val_t *acl, acl_action_t action,
continue;
}
/* Compare key names. */
/* Compare key names (both in lower-case). */
const knot_dname_t *key_name = conf_dname(&key_val);
if (knot_dname_cmp(key_name, tsig->name) != 0) {
if (!knot_dname_is_equal(key_name, tsig->name)) {
conf_val_next(&key_val);
continue;
}
......
......@@ -469,7 +469,7 @@ static int add_node(zone_contents_t *zone, zone_node_t *node, bool create_parent
zone_node_t *next_node = NULL;
const uint8_t *parent = knot_wire_next_label(node->owner, NULL);
if (knot_dname_cmp(zone->apex->owner, parent) == 0) {
if (knot_dname_is_equal(zone->apex->owner, parent)) {
node_set_parent(node, zone->apex);
// check if the node is not wildcard child of the parent
......
......@@ -642,8 +642,11 @@ void knot_dname_free(knot_dname_t **name, knot_mm_t *mm)
_public_
int knot_dname_cmp(const knot_dname_t *d1, const knot_dname_t *d2)
{
/* This would be hard to catch since -1 is a good result, assert instead. */
assert(d1 != NULL || d2 != NULL);
if (d1 == NULL) {
return -1;
} else if (d2 == NULL) {
return 1;
}
/* Convert to lookup format. */
knot_dname_storage_t lf1_storage;
......@@ -652,7 +655,7 @@ int knot_dname_cmp(const knot_dname_t *d1, const knot_dname_t *d2)
uint8_t *lf1 = knot_dname_lf(d1, &lf1_storage);
uint8_t *lf2 = knot_dname_lf(d2, &lf2_storage);
assert(lf1 && lf2);
// TODO: lowercase?
/* Compare common part. */
uint8_t common = lf1[0];
if (common > lf2[0]) {
......@@ -676,8 +679,9 @@ int knot_dname_cmp(const knot_dname_t *d1, const knot_dname_t *d2)
_public_
bool knot_dname_is_equal(const knot_dname_t *d1, const knot_dname_t *d2)
{
assert(d1);
assert(d2);
if (d1 == NULL || d2 == NULL) {
return false;
}
while (*d1 != '\0' || *d2 != '\0') {
if (label_is_equal(d1, d2)) {
......@@ -694,8 +698,9 @@ bool knot_dname_is_equal(const knot_dname_t *d1, const knot_dname_t *d2)
_public_
bool knot_dname_label_is_equal(const uint8_t *label1, const uint8_t *label2)
{
assert(label1);
assert(label2);
if (label1 == NULL || label2 == NULL) {
return false;
}
/* Check that they have the same length */
if (*label1 != *label2) {
......
......@@ -289,11 +289,7 @@ knot_dname_t *knot_dname_replace_suffix(const knot_dname_t *name, unsigned label
void knot_dname_free(knot_dname_t **name, knot_mm_t *mm);
/*!
* \brief Compares two domain names by labels (case insensitive).
*
* \warning Since it would be hard to catch errors, because negative value
* is also a good result, there are assertions that expect neither
* d1 or d2 to be NULL.
* \brief Compares two domain names by labels (case sensitive).
*
* \param d1 First domain name.
* \param d2 Second domain name.
......@@ -308,8 +304,6 @@ int knot_dname_cmp(const knot_dname_t *d1, const knot_dname_t *d2);
/*!
* \brief Compares two domain names (case sensitive).
*
* \warning d1 and d2 must not be NULL.
*
* \param d1 First domain name.
* \param d2 Second domain name.
*
......@@ -322,8 +316,6 @@ bool knot_dname_is_equal(const knot_dname_t *d1, const knot_dname_t *d2);
/*!
* \brief Compares two domain name labels (case insensitive).
*
* \warning label1 and label2 must not be NULL.
*
* \param label1 First label.
* \param label2 Second label.
*
......
......@@ -65,7 +65,7 @@ static int check_key(const knot_rrset_t *tsig_rr, const knot_tsig_key_t *tsig_ke
return KNOT_EMALF;
}
if (knot_dname_cmp(tsig_name, tsig_key->name) != 0) {
if (!knot_dname_is_equal(tsig_name, tsig_key->name)) {
return KNOT_TSIG_EBADKEY;
}
......
......@@ -517,12 +517,9 @@ static void check_reply_question(const knot_pkt_t *reply,
return;
}
int name_diff = knot_dname_cmp(knot_pkt_qname(reply),
knot_pkt_qname(query));
if (knot_pkt_qclass(reply) != knot_pkt_qclass(query) ||
knot_pkt_qtype(reply) != knot_pkt_qtype(query) ||
name_diff != 0) {
if (!knot_dname_is_equal(knot_pkt_qname(reply), knot_pkt_qname(query)) ||
knot_pkt_qclass(reply) != knot_pkt_qclass(query) ||
knot_pkt_qtype(reply) != knot_pkt_qtype(query)) {
WARN("query/response question sections are different\n");
return;
}
......
......@@ -822,7 +822,7 @@ static void test_chain(void)
knot_dname_t *dname = NULL;
ret = knot_edns_chain_parse(&dname, (uint8_t *)t->dname, t->opt_len);
is_int(KNOT_EOK, ret, "%s: dname %s, parse, return", __func__, t->msg);
ok(knot_dname_cmp(dname, t->dname) == 0, "%s: dname %s, parse, value",
ok(knot_dname_is_equal(dname, t->dname), "%s: dname %s, parse, value",
__func__, t->msg);
knot_dname_free(&dname, 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
......@@ -34,7 +34,8 @@ static void _test_nsec_next(const char *msg,
const knot_dname_t *expected)
{
knot_dname_t *next = online_nsec_next(input, apex);
ok(next != NULL && knot_dname_cmp(next, expected) == 0, "nsec_next, %s", msg);
ok(next != NULL && knot_dname_is_equal(next, expected),
"nsec_next, %s", msg);
knot_dname_free(&next, NULL);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment