Commit 6246c420 authored by Lubos Slovak's avatar Lubos Slovak

Changed dname so that it can hold non-FQDN names.

TODO/BUG: resulted in some random segfault crashes of RDATA tests.

refs #5
parent 9da8f110
......@@ -84,11 +84,14 @@ static uint dnslib_dname_str_to_wire(const char *name, uint size,
assert(ch >= (const uint8_t *)name);
}
// put 0 for root label regardless whether the name ended with .
--w;
debug_dnslib_dname("Position %u (%p): character: (null)\n",
w - *wire, w);
*w = 0;
// put 0 for root label if the name ended with .
--ch;
if (*ch == '.') {
--w;
debug_dnslib_dname("Position %u (%p): character: (null)\n",
w - *wire, w);
*w = 0;
}
//memcpy(*wire, name, size);
return wire_size;
......@@ -184,15 +187,15 @@ char *dnslib_dname_to_str(const dnslib_dname_t *dname)
uint8_t *w = dname->name;
char *ch = name;
while (*w != 0) {
uint8_t *next = w + *w + 1;
// skip label length
++w;
while (w != next) {
*(ch++) = *(w++);
}
// insert . at the end of label
int i = 0;
while (i < dname->size && *w != 0) {
int label_size = *(w++);
// copy the label
memcpy(ch, w, label_size);
i += label_size;
ch += label_size;
w += label_size;
*(ch++) = '.';
}
......
......@@ -52,8 +52,8 @@ dnslib_dname_t *dnslib_dname_new();
* \brief Creates a dname structure from domain name given in presentation
* format.
*
* The resulting domain name is stored in wire format and ALWAYS ENDS WITH 0,
* e.g. is a FQDN even if the given domain name was not.
* The resulting domain name is stored in wire format, but it may not end with
* root label (\0).
*
* \param name Domain name in presentation format (labels separated by dots).
* \param size Size of the domain name (count of characters with all dots).
......@@ -62,18 +62,15 @@ dnslib_dname_t *dnslib_dname_new();
*
* \return Newly allocated and initialized dname structure representing the
* given domain name.
*
* \todo Check if the FQDN issue is OK.
*/
dnslib_dname_t *dnslib_dname_new_from_str(char *name, uint size,
struct dnslib_node *node);
struct dnslib_node *node);
/*!
* \brief Creates a dname structure from domain name given in wire format.
*
* \note The name is copied into the structure.
* \note If the given name is not a FQDN, the result will be neither. This
* does not correspond to the behaviour of dnslib_dname_new_from_str().
* \note If the given name is not a FQDN, the result will be neither.
*
* \param name Domain name in wire format.
* \param size Size of the domain name in octets.
......@@ -83,8 +80,7 @@ dnslib_dname_t *dnslib_dname_new_from_str(char *name, uint size,
* \return Newly allocated and initialized dname structure representing the
* given domain name.
*
* \todo Address the FQDN issue.
* \todo This function does not check if the given data is in correct wir
* \todo This function does not check if the given data is in correct wire
* format at all. It thus creates a invalid domain name, which if passed
* e.g. to dnslib_dname_to_str() may result in crash. Decide whether it
* is OK to retain this and check the data in other functions before
......
......@@ -24,7 +24,7 @@
//#define ZDB_DEBUG_INSERT_CHECK
//#define ZN_DEBUG
//#define ZP_DEBUG_PARSE
#define DNSLIB_DNAME_DEBUG
//#define DNSLIB_DNAME_DEBUG
//#define SERVER_DEBUG
//#define DT_DEBUG
//#define NET_DEBUG
......
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