mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +00:00
Add 'list' field.
Fixed name length bug in _fromtext(), _fromwire(). The previous way of computing the length failed if the length of the target buffer was > 255.
This commit is contained in:
@@ -141,7 +141,8 @@ static unsigned char maptolower[] = {
|
|||||||
static struct dns_name root = {
|
static struct dns_name root = {
|
||||||
NAME_MAGIC,
|
NAME_MAGIC,
|
||||||
(unsigned char *)"", 1, 1, NULL,
|
(unsigned char *)"", 1, 1, NULL,
|
||||||
{(void *)-1, (void *)-1}
|
{(void *)-1, (void *)-1},
|
||||||
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
dns_name_t *dns_rootname = &root;
|
dns_name_t *dns_rootname = &root;
|
||||||
@@ -254,6 +255,7 @@ dns_name_init(dns_name_t *name, unsigned char *offsets) {
|
|||||||
name->labels = 0;
|
name->labels = 0;
|
||||||
name->offsets = offsets;
|
name->offsets = offsets;
|
||||||
ISC_LINK_INIT(name, link);
|
ISC_LINK_INIT(name, link);
|
||||||
|
ISC_LIST_INIT(name->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -568,7 +570,6 @@ dns_name_fromregion(dns_name_t *name, isc_region_t *r) {
|
|||||||
|
|
||||||
INIT_OFFSETS(name, offsets, odata);
|
INIT_OFFSETS(name, offsets, odata);
|
||||||
|
|
||||||
name->magic = NAME_MAGIC;
|
|
||||||
name->ndata = r->base;
|
name->ndata = r->base;
|
||||||
name->length = r->length;
|
name->length = r->length;
|
||||||
|
|
||||||
@@ -602,7 +603,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
char c;
|
char c;
|
||||||
ft_state state, kind;
|
ft_state state, kind;
|
||||||
unsigned int value, count, tbcount, bitlength, maxlength;
|
unsigned int value, count, tbcount, bitlength, maxlength;
|
||||||
unsigned int n1, n2, vlen, tlen, nrem, digits, labels, tused;
|
unsigned int n1, n2, vlen, tlen, nrem, nused, digits, labels, tused;
|
||||||
isc_boolean_t done, saw_bitstring;
|
isc_boolean_t done, saw_bitstring;
|
||||||
unsigned char dqchars[4];
|
unsigned char dqchars[4];
|
||||||
unsigned char *offsets;
|
unsigned char *offsets;
|
||||||
@@ -657,6 +658,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
nrem = target->length - target->used;
|
nrem = target->length - target->used;
|
||||||
if (nrem > 255)
|
if (nrem > 255)
|
||||||
nrem = 255;
|
nrem = 255;
|
||||||
|
nused = 0;
|
||||||
labels = 0;
|
labels = 0;
|
||||||
done = ISC_FALSE;
|
done = ISC_FALSE;
|
||||||
saw_bitstring = ISC_FALSE;
|
saw_bitstring = ISC_FALSE;
|
||||||
@@ -679,6 +681,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
labels++;
|
labels++;
|
||||||
*ndata++ = 0;
|
*ndata++ = 0;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -687,6 +690,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
label = ndata;
|
label = ndata;
|
||||||
ndata++;
|
ndata++;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
count = 0;
|
count = 0;
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
state = ft_initialescape;
|
state = ft_initialescape;
|
||||||
@@ -705,6 +709,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
labels++;
|
labels++;
|
||||||
*ndata++ = 0;
|
*ndata++ = 0;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
}
|
}
|
||||||
state = ft_start;
|
state = ft_start;
|
||||||
@@ -719,6 +724,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
c = maptolower[(int)c];
|
c = maptolower[(int)c];
|
||||||
*ndata++ = c;
|
*ndata++ = c;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ft_initialescape:
|
case ft_initialescape:
|
||||||
@@ -730,6 +736,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
label = ndata;
|
label = ndata;
|
||||||
ndata++;
|
ndata++;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
kind = ft_ordinary;
|
kind = ft_ordinary;
|
||||||
@@ -745,6 +752,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
c = maptolower[(int)c];
|
c = maptolower[(int)c];
|
||||||
*ndata++ = c;
|
*ndata++ = c;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
state = ft_ordinary;
|
state = ft_ordinary;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -768,6 +776,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
value = maptolower[value];
|
value = maptolower[value];
|
||||||
*ndata++ = value;
|
*ndata++ = value;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
state = ft_ordinary;
|
state = ft_ordinary;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -817,6 +826,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (count == 8) {
|
if (count == 8) {
|
||||||
*ndata++ = value;
|
*ndata++ = value;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -834,15 +844,18 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (count == 8) {
|
if (count == 8) {
|
||||||
*ndata++ = value;
|
*ndata++ = value;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
count = 0;
|
count = 0;
|
||||||
} else if (count == 9) {
|
} else if (count == 9) {
|
||||||
*ndata++ = (value >> 1);
|
*ndata++ = (value >> 1);
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
value &= 1;
|
value &= 1;
|
||||||
count = 1;
|
count = 1;
|
||||||
} else if (count == 10) {
|
} else if (count == 10) {
|
||||||
*ndata++ = (value >> 2);
|
*ndata++ = (value >> 2);
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
value &= 3;
|
value &= 3;
|
||||||
count = 2;
|
count = 2;
|
||||||
}
|
}
|
||||||
@@ -861,6 +874,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (count == 8) {
|
if (count == 8) {
|
||||||
*ndata++ = value;
|
*ndata++ = value;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -911,6 +925,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
value <<= (8 - n1);
|
value <<= (8 - n1);
|
||||||
*ndata++ = value;
|
*ndata++ = value;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
}
|
}
|
||||||
if (bitlength != 0) {
|
if (bitlength != 0) {
|
||||||
if (bitlength > tbcount)
|
if (bitlength > tbcount)
|
||||||
@@ -970,6 +985,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
for (n2 = 0; n2 < n1; n2++) {
|
for (n2 = 0; n2 < n1; n2++) {
|
||||||
*ndata++ = dqchars[n2];
|
*ndata++ = dqchars[n2];
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bitlength == 256)
|
if (bitlength == 256)
|
||||||
@@ -1000,6 +1016,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
labels++;
|
labels++;
|
||||||
*ndata++ = 0;
|
*ndata++ = 0;
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
}
|
}
|
||||||
state = ft_start;
|
state = ft_start;
|
||||||
@@ -1028,6 +1045,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
label = origin->ndata;
|
label = origin->ndata;
|
||||||
n1 = origin->length;
|
n1 = origin->length;
|
||||||
nrem -= n1;
|
nrem -= n1;
|
||||||
|
nused += n1;
|
||||||
labels += origin->labels;
|
labels += origin->labels;
|
||||||
while (n1 > 0) {
|
while (n1 > 0) {
|
||||||
c = *label++;
|
c = *label++;
|
||||||
@@ -1043,7 +1061,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||||||
name->magic = NAME_MAGIC;
|
name->magic = NAME_MAGIC;
|
||||||
name->ndata = (unsigned char *)target->base + target->used;
|
name->ndata = (unsigned char *)target->base + target->used;
|
||||||
name->labels = labels;
|
name->labels = labels;
|
||||||
name->length = target->length - target->used - nrem;
|
name->length = nused;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We should build the offsets table directly.
|
* We should build the offsets table directly.
|
||||||
@@ -1412,7 +1430,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
isc_buffer_t *target)
|
isc_buffer_t *target)
|
||||||
{
|
{
|
||||||
unsigned char *cdata, *ndata;
|
unsigned char *cdata, *ndata;
|
||||||
unsigned int cused, hops, nrem, labels, n;
|
unsigned int cused, hops, nrem, nused, labels, n;
|
||||||
unsigned int current, new_current, biggest_pointer;
|
unsigned int current, new_current, biggest_pointer;
|
||||||
isc_boolean_t saw_bitstring, done;
|
isc_boolean_t saw_bitstring, done;
|
||||||
fw_state state = fw_start;
|
fw_state state = fw_start;
|
||||||
@@ -1457,6 +1475,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
nrem = target->length - target->used;
|
nrem = target->length - target->used;
|
||||||
if (nrem > 255)
|
if (nrem > 255)
|
||||||
nrem = 255;
|
nrem = 255;
|
||||||
|
nused = 0;
|
||||||
cdata = (unsigned char *)source->base + source->current;
|
cdata = (unsigned char *)source->base + source->current;
|
||||||
cused = 0;
|
cused = 0;
|
||||||
current = source->current;
|
current = source->current;
|
||||||
@@ -1480,6 +1499,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (nrem < c + 1)
|
if (nrem < c + 1)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
nrem -= c + 1;
|
nrem -= c + 1;
|
||||||
|
nused += c + 1;
|
||||||
*ndata++ = c;
|
*ndata++ = c;
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
done = ISC_TRUE;
|
done = ISC_TRUE;
|
||||||
@@ -1500,6 +1520,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (nrem == 0)
|
if (nrem == 0)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
nrem--;
|
nrem--;
|
||||||
|
nused++;
|
||||||
*ndata++ = c;
|
*ndata++ = c;
|
||||||
saw_bitstring = ISC_TRUE;
|
saw_bitstring = ISC_TRUE;
|
||||||
state = fw_bitstring;
|
state = fw_bitstring;
|
||||||
@@ -1540,6 +1561,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
if (nrem < c + 1)
|
if (nrem < c + 1)
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
nrem -= c + 1;
|
nrem -= c + 1;
|
||||||
|
nused += c + 1;
|
||||||
*ndata++ = c;
|
*ndata++ = c;
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
c = 256;
|
c = 256;
|
||||||
@@ -1578,7 +1600,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source,
|
|||||||
name->magic = NAME_MAGIC;
|
name->magic = NAME_MAGIC;
|
||||||
name->ndata = (unsigned char *)target->base + target->used;
|
name->ndata = (unsigned char *)target->base + target->used;
|
||||||
name->labels = labels;
|
name->labels = labels;
|
||||||
name->length = target->length - target->used - nrem;
|
name->length = nused;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We should build the offsets table directly.
|
* We should build the offsets table directly.
|
||||||
|
Reference in New Issue
Block a user