summaryrefslogtreecommitdiff
path: root/src/libknot
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-03-01 13:23:59 +0100
committerOndřej Surý <ondrej@sury.org>2013-03-01 13:23:59 +0100
commit621622287b6da91b755565b9133c4e53f8a0251d (patch)
tree5e5e24353518b7d62ad65d552d3cd6f1899f7391 /src/libknot
parent2729227efaac366293e70770b6e82e7e775a2605 (diff)
downloadknot-621622287b6da91b755565b9133c4e53f8a0251d.tar.gz
Imported Upstream version 1.2.0~rc3upstream/1.2.0_rc3
Diffstat (limited to 'src/libknot')
-rw-r--r--src/libknot/hash/cuckoo-hash-table.c45
-rw-r--r--src/libknot/nameserver/name-server.c4
-rw-r--r--src/libknot/packet/packet.c3
-rw-r--r--src/libknot/packet/packet.h14
-rw-r--r--src/libknot/packet/response.c3
-rw-r--r--src/libknot/rdata.c3
-rw-r--r--src/libknot/rrset.c3
-rw-r--r--src/libknot/updates/ddns.c3
-rw-r--r--src/libknot/zone/zone-contents.c7
-rw-r--r--src/libknot/zone/zone-tree.c2
-rw-r--r--src/libknot/zone/zone.h6
11 files changed, 75 insertions, 18 deletions
diff --git a/src/libknot/hash/cuckoo-hash-table.c b/src/libknot/hash/cuckoo-hash-table.c
index 7d454a9..a2a6d3f 100644
--- a/src/libknot/hash/cuckoo-hash-table.c
+++ b/src/libknot/hash/cuckoo-hash-table.c
@@ -96,7 +96,9 @@ static const uint8_t FLAG_REHASH = 0x4; // 00000100
/*! \brief Clears the table / item flags. */
static inline void CLEAR_FLAGS(uint8_t *flags)
{
- *flags = (uint8_t)0x0;
+ if (flags) {
+ *flags = (uint8_t)0x0;
+ }
}
/*! \brief Returns the generation stored in the flags. */
@@ -120,7 +122,9 @@ static inline int IS_GENERATION1(uint8_t flags)
/*! \brief Sets the generation stored in the flags to 1. */
static inline void SET_GENERATION1(uint8_t *flags)
{
- *flags = ((*flags) & ~FLAG_GENERATION2) | FLAG_GENERATION1;
+ if (flags) {
+ *flags = ((*flags) & ~FLAG_GENERATION2) | FLAG_GENERATION1;
+ }
}
/*! \brief Checks if the generation stored in the flags is 2. */
@@ -132,19 +136,26 @@ static inline int IS_GENERATION2(uint8_t flags)
/*! \brief Sets the generation stored in the flags to 2. */
static inline void SET_GENERATION2(uint8_t *flags)
{
- *flags = ((*flags) & ~FLAG_GENERATION1) | FLAG_GENERATION2;
+ if (flags) {
+ *flags = ((*flags) & ~FLAG_GENERATION1) | FLAG_GENERATION2;
+ }
}
/*! \brief Sets the generation stored in the flags to the given generation. */
static inline void SET_GENERATION(uint8_t *flags, uint8_t generation)
{
- *flags = ((*flags) & ~FLAG_GENERATION_BOTH) | generation;
+ if (flags) {
+ *flags = ((*flags) & ~FLAG_GENERATION_BOTH) | generation;
+ }
}
/*! \brief Sets the generation stored in the flags to the next one (cyclic). */
static inline uint8_t SET_NEXT_GENERATION(uint8_t *flags)
{
- return ((*flags) ^= FLAG_GENERATION_BOTH);
+ if (flags) {
+ return ((*flags) ^= FLAG_GENERATION_BOTH);
+ }
+ return 0;
}
/*! \brief Returns the next generation to the one stored in flags (cyclic). */
@@ -156,13 +167,17 @@ static inline uint8_t NEXT_GENERATION(uint8_t flags)
/*! \brief Sets the rehashing flag to the flags. */
static inline void SET_REHASHING_ON(uint8_t *flags)
{
- *flags = (*flags | FLAG_REHASH);
+ if (flags) {
+ *flags = (*flags | FLAG_REHASH);
+ }
}
/*! \brief Removes the rehashing flag from the flags. */
static inline void SET_REHASHING_OFF(uint8_t *flags)
{
- *flags = (*flags & ~FLAG_REHASH);
+ if (flags) {
+ *flags = (*flags & ~FLAG_REHASH);
+ }
}
/*! \brief Checks if the rehashing flag is set in the flags. */
@@ -1245,7 +1260,7 @@ int ck_shallow_copy(const ck_hash_table_t *from, ck_hash_table_t **to)
// copy the stash - we must explicitly copy each stash item, but do not
// copy the ck_hash_table_item_t within them.
ck_stash_item_t *si = from->stash;
- ck_stash_item_t **pos = &(*to)->stash;
+ ck_stash_item_t *last = NULL;
dbg_ck_verb("Copying hash table stash.\n");
while (si != NULL) {
ck_stash_item_t *si_new = (ck_stash_item_t *)
@@ -1272,8 +1287,13 @@ int ck_shallow_copy(const ck_hash_table_t *from, ck_hash_table_t **to)
si->item->key);
si_new->item = si->item;
- *pos = si_new;
- pos = &si_new->next;
+ si_new->next = NULL;
+ if (last == NULL) {
+ (*to)->stash = si_new;
+ } else {
+ last->next = si_new;
+ }
+ last = si_new;
si = si->next;
dbg_ck_exec_detail(
@@ -1290,8 +1310,6 @@ dbg_ck_exec_detail(
);
}
- *pos = NULL;
-
// there should be no item being hashed right now
/*! \todo This operation should not be done while inserting / rehashing.
*/
@@ -1534,6 +1552,9 @@ int ck_apply(ck_hash_table_t *table,
int ck_rehash(ck_hash_table_t *table)
{
dbg_ck_hash("Rehashing items in table.\n");
+ if (!table) {
+ return -1;
+ }
SET_REHASHING_ON(&table->generation);
ck_stash_item_t *free_stash_items = NULL;
diff --git a/src/libknot/nameserver/name-server.c b/src/libknot/nameserver/name-server.c
index 8238d7e..b81a2c0 100644
--- a/src/libknot/nameserver/name-server.c
+++ b/src/libknot/nameserver/name-server.c
@@ -189,6 +189,7 @@ static int ns_check_wildcard(const knot_dname_t *name, knot_packet_t *resp,
assert(*rrset != NULL);
if (knot_dname_is_wildcard((*rrset)->owner)) {
+ resp->flags |= KNOT_PF_WILDCARD; /* Mark */
knot_rrset_t *synth_rrset =
ns_synth_from_wildcard(*rrset, name);
if (synth_rrset == NULL) {
@@ -254,7 +255,8 @@ static int ns_add_rrsigs(knot_rrset_t *rrset, knot_packet_t *resp,
dbg_ns_detail("RRSIGS: %p\n", knot_rrset_rrsigs(rrset));
if (DNSSEC_ENABLED
- && knot_query_dnssec_requested(knot_packet_query(resp))
+ && (knot_query_dnssec_requested(knot_packet_query(resp))
+ || knot_packet_qtype(resp) == KNOT_RRTYPE_ANY)
&& (rrsigs = knot_rrset_get_rrsigs(rrset)) != NULL) {
if (name != NULL) {
int ret = ns_check_wildcard(name, resp, &rrsigs);
diff --git a/src/libknot/packet/packet.c b/src/libknot/packet/packet.c
index 9b7e7c7..b6381c4 100644
--- a/src/libknot/packet/packet.c
+++ b/src/libknot/packet/packet.c
@@ -291,7 +291,6 @@ static int knot_packet_parse_question(const uint8_t *wire, size_t *pos,
dbg_packet_verb("Parsing dname starting on position %zu and "
"%zu bytes long.\n", *pos, i - *pos + 1);
dbg_packet_verb("Alloc: %d\n", alloc);
- size_t bp = *pos;
if (alloc) {
question->qname = knot_dname_parse_from_wire(wire, pos,
i + 1,
@@ -300,6 +299,7 @@ static int knot_packet_parse_question(const uint8_t *wire, size_t *pos,
return KNOT_ENOMEM;
}
} else {
+ assert(question->qname != NULL); /* When alloc=0, must be set. */
void *parsed = knot_dname_parse_from_wire(wire, pos,
i + 1,
NULL, question->qname);
@@ -344,6 +344,7 @@ static int knot_packet_realloc_rrsets(const knot_rrset_t ***rrsets,
new_max_count * sizeof(knot_rrset_t *));
CHECK_ALLOC_LOG(new_rrsets, KNOT_ENOMEM);
+ memset(new_rrsets, 0, new_max_count * sizeof(knot_rrset_t *));
memcpy(new_rrsets, *rrsets, (*max_count) * sizeof(knot_rrset_t *));
*rrsets = new_rrsets;
diff --git a/src/libknot/packet/packet.h b/src/libknot/packet/packet.h
index 5a95bae..ba85aed 100644
--- a/src/libknot/packet/packet.h
+++ b/src/libknot/packet/packet.h
@@ -34,6 +34,7 @@
#include "rrset.h"
#include "edns.h"
#include "zone/node.h"
+#include "zone/zone.h"
/*----------------------------------------------------------------------------*/
/*!
@@ -163,11 +164,24 @@ struct knot_packet {
size_t tsig_size; /*!< Space to reserve for the TSIG RR. */
knot_rrset_t *tsig_rr; /*!< TSIG RR stored in the packet. */
+ uint16_t flags; /*!< Packet flags. */
+ const knot_zone_t *zone; /*!< Associated zone. */
};
typedef struct knot_packet knot_packet_t;
/*----------------------------------------------------------------------------*/
+
+/*!
+ * \brief Packet flags.
+ */
+enum {
+ KNOT_PF_NULL = 0 << 0, /*!< No flags. */
+ KNOT_PF_QUERY = 1 << 0, /*!< Packet is query. */
+ KNOT_PF_WILDCARD = 1 << 1, /*!< Query to wildcard name. */
+ KNOT_PF_RESPONSE = 1 << 2 /*!< Packet is response. */
+};
+
/*!
* \brief Default sizes for response structure parts and steps for increasing
* them.
diff --git a/src/libknot/packet/response.c b/src/libknot/packet/response.c
index 476c6b3..69678c7 100644
--- a/src/libknot/packet/response.c
+++ b/src/libknot/packet/response.c
@@ -368,6 +368,9 @@ static int knot_response_compress_dname(const knot_dname_t *dname,
knot_compr_t *compr, uint8_t *dname_wire, size_t max, int compr_cs)
{
int size = 0;
+ if (!dname || !compr || !dname_wire) {
+ return KNOT_EINVAL;
+ }
// try to find the name or one of its ancestors in the compr. table
#ifdef COMPRESSION_PEDANTIC
diff --git a/src/libknot/rdata.c b/src/libknot/rdata.c
index 352bb6c..d59b4e0 100644
--- a/src/libknot/rdata.c
+++ b/src/libknot/rdata.c
@@ -215,6 +215,9 @@ int knot_rdata_from_wire(knot_rdata_t *rdata, const uint8_t *wire,
int i = 0;
uint8_t item_type;
size_t parsed = 0;
+ if (!rdata || !wire || !pos || !desc) {
+ return KNOT_EINVAL;
+ }
if (rdlength == 0) {
rdata->items = NULL;
diff --git a/src/libknot/rrset.c b/src/libknot/rrset.c
index 84d5075..f5a9f5f 100644
--- a/src/libknot/rrset.c
+++ b/src/libknot/rrset.c
@@ -346,6 +346,9 @@ knot_rdata_t *knot_rrset_get_rdata(knot_rrset_t *rrset)
knot_rdata_t *knot_rrset_rdata_get_next(knot_rrset_t *rrset,
knot_rdata_t *rdata)
{
+ if (!rdata || !rrset) {
+ return NULL;
+ }
if (rdata->next == rrset->rdata) {
return NULL;
} else {
diff --git a/src/libknot/updates/ddns.c b/src/libknot/updates/ddns.c
index 90a578f..79b28fb 100644
--- a/src/libknot/updates/ddns.c
+++ b/src/libknot/updates/ddns.c
@@ -2206,6 +2206,9 @@ static int knot_ddns_process_rr(const knot_rrset_t *rr,
if (knot_rrset_class(rr) == knot_zone_contents_class(zone)) {
return knot_ddns_process_add(rr, node, zone, changeset,
changes, rr_copy);
+ } else if (node == NULL) {
+ // Removing from non-existing node, just ignore the entry
+ return KNOT_EOK;
} else if (knot_rrset_class(rr) == KNOT_CLASS_NONE) {
return knot_ddns_process_rem_rr(rr, node, zone, changeset,
changes, qclass);
diff --git a/src/libknot/zone/zone-contents.c b/src/libknot/zone/zone-contents.c
index bdc268b..90aee0d 100644
--- a/src/libknot/zone/zone-contents.c
+++ b/src/libknot/zone/zone-contents.c
@@ -3158,7 +3158,7 @@ static void knot_zc_integrity_check_parent(const knot_node_t *node,
!= node) {
char *wc = (knot_node_wildcard_child(
check_data->parent) == NULL)
- ? "none"
+ ? strdup("none")
: knot_dname_to_str(knot_node_owner(
knot_node_wildcard_child(
check_data->parent)));
@@ -3167,8 +3167,8 @@ static void knot_zc_integrity_check_parent(const knot_node_t *node,
pname, wc, name);
if (knot_node_wildcard_child(
check_data->parent) != NULL) {
- free(wc);
}
+ free(wc);
++check_data->errors;
}
@@ -3229,6 +3229,9 @@ static int knot_zc_integrity_check_find_dname(const knot_zone_contents_t *zone,
const char *node_name)
{
int ret = 0;
+ if (!zone || !to_find || !node_name) {
+ return KNOT_EINVAL;
+ }
knot_dname_t *found = knot_dname_table_find_dname(zone->dname_table,
(knot_dname_t *)to_find);
diff --git a/src/libknot/zone/zone-tree.c b/src/libknot/zone/zone-tree.c
index ceaa6a9..1d7991e 100644
--- a/src/libknot/zone/zone-tree.c
+++ b/src/libknot/zone/zone-tree.c
@@ -269,7 +269,7 @@ int knot_zone_tree_find_less_or_equal(knot_zone_tree_t *tree,
return KNOT_EINVAL;
}
- knot_node_t *f, *p;
+ knot_node_t *f = NULL, *p = NULL;
int ret = knot_zone_tree_get_less_or_equal(tree, owner, &f, &p);
*found = f;
diff --git a/src/libknot/zone/zone.h b/src/libknot/zone/zone.h
index 31ff2ac..26a5e2a 100644
--- a/src/libknot/zone/zone.h
+++ b/src/libknot/zone/zone.h
@@ -193,7 +193,11 @@ void knot_zone_set_dtor(knot_zone_t *zone, int (*dtor)(struct knot_zone *));
* \param zone Zone.
*/
static inline unsigned knot_zone_flags(knot_zone_t *zone) {
- return zone->flags;
+ if (zone) {
+ return zone->flags;
+ } else {
+ return 0;
+ }
}
/*!