Skip to content
Snippets Groups Projects
Commit db1b3303 authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Fixed remarks found in the code review for merge request #53

parent fa34ab3b
No related branches found
No related tags found
No related merge requests found
......@@ -361,7 +361,7 @@ static void conf_zone_start(void *scanner, char *name) {
/* Directly discard dname, won't be needed. */
add_tail(&new_config->zones, &this_zone->n);
*hattrie_get(new_config->names, (const char*)dn, knot_dname_size(dn)) = (void *)1;
*hattrie_get(new_config->names, (const char *)dn, knot_dname_size(dn)) = (void *)1;
++new_config->zones_count;
knot_dname_free(&dn);
}
......
......@@ -526,7 +526,7 @@ int remote_answer(int fd, server_t *s, knot_packet_t *pkt, uint8_t* rwire, size_
}
knot_dname_t *realm = knot_dname_from_str(KNOT_CTL_REALM,
KNOT_CTL_REALM_LEN);
KNOT_CTL_REALM_LEN);
if (!knot_dname_is_sub(qname, realm) != 0) {
dbg_server("remote: qname != *%s\n", KNOT_CTL_REALM_EXT);
knot_dname_free(&realm);
......
......@@ -19,7 +19,7 @@
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h> // tolower()
#include <ctype.h>
#include <inttypes.h>
#include "common.h"
......@@ -47,13 +47,15 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos)
const uint8_t *name = pkt + *pos;
const uint8_t *endp = pkt + maxpos;
int parsed = knot_dname_wire_check(name, endp, pkt);
if (parsed < 0)
if (parsed < 0) {
return NULL;
}
/* Calculate decompressed length. */
int decompressed_len = knot_dname_realsize(name, pkt);
if (decompressed_len < parsed)
if (decompressed_len < 1) {
return NULL;
}
/* Allocate space for the name. */
knot_dname_t *res = malloc(decompressed_len);
......@@ -510,7 +512,7 @@ int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
int wire_len = 0;
int name_len = 1; /* Keep \x00 terminal label in advance. */
uint8_t is_compressed = 0;
bool is_compressed = false;
uint8_t labels = 0;
while (*name != '\0') {
......@@ -519,8 +521,8 @@ int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
if (name + 2 > endp)
return KNOT_ESPACE;
/* Reject more labels. */
if (labels == KNOT_DNAME_MAXLABELS - 1)
/* Reject more labels (last label is terminal). */
if (labels >= KNOT_DNAME_MAXLABELS - 1)
return KNOT_EMALF;
if (knot_wire_is_pointer(name)) {
......@@ -536,7 +538,7 @@ int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
name = pkt + ptr; /* Hop to compressed label */
if (!is_compressed) { /* Measure compressed size only */
wire_len += sizeof(uint16_t);
is_compressed = 1;
is_compressed = true;
}
} else {
/* Check label length (maximum 63 bytes allowed). */
......
......@@ -96,6 +96,12 @@ int knot_dname_to_wire(uint8_t *dst, const knot_dname_t *src, size_t maxlen);
/*!
* \brief Write unpacked name (i.e. compression pointers expanded)
*
* \note The function is very similar to the knot_dname_to_wire(), except
* it expands compression pointers. E.g. you want to use knot_dname_unpack()
* if you copy a dname from incoming packet to some persistent storage.
* And you want to use knot_dname_to_wire() if you know the name is not
* compressed or you want to copy it 1:1.
*
* \param dst Destination wire.
* \param src Source name.
* \param maxlen Maximum destination wire size.
......@@ -111,6 +117,8 @@ int knot_dname_unpack(uint8_t *dst, const knot_dname_t *src,
*
* \note Allocates new memory, remember to free it.
*
* \todo The function doesn't process escaped characters like \DDD or \X.
*
* \param dname Domain name to be converted.
*
* \return 0-terminated string representing the given domain name in
......
......@@ -47,7 +47,7 @@ typedef struct {
* \retval packet if success.
* \retval NULL if error.
*/
knot_packet_t* create_empty_packet(const size_t max_size);
knot_packet_t* create_empty_packet(const size_t max_size);
/*!
* \brief Prints information header for transfer.
......
......@@ -81,7 +81,7 @@ static knot_packet_t* create_query_packet(const query_t *query,
// Create QNAME from string.
knot_dname_t *qname = knot_dname_from_str(query->owner,
strlen(query->owner));
strlen(query->owner));
if (qname == NULL) {
knot_packet_free(&packet);
return NULL;
......@@ -220,7 +220,7 @@ static void check_reply_question(const knot_packet_t *reply,
}
int name_diff = knot_dname_cmp(knot_packet_qname(reply),
knot_packet_qname(query));
knot_packet_qname(query));
if (knot_packet_qclass(reply) != knot_packet_qclass(query) ||
knot_packet_qtype(reply) != knot_packet_qtype(query) ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment