Commit b8f16556 authored by Simon Kelley's avatar Simon Kelley

Tweaks to previous, DNS label charset commit.

parent cbe379ad
...@@ -144,5 +144,9 @@ struct dns_header { ...@@ -144,5 +144,9 @@ struct dns_header {
(!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1)) (!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1))
/* Escape character in our presentation format for names. /* Escape character in our presentation format for names.
Cannot be '.' or /000 and must be !isprint() */ Cannot be '.' or /000 and must be !isprint().
Note that escaped chars are stored as
<NAME_ESCAPE> <orig-char+1>
to ensure that the escaped form of /000 doesn't include /000
*/
#define NAME_ESCAPE 1 #define NAME_ESCAPE 1
...@@ -341,9 +341,11 @@ static int to_wire(char *name) ...@@ -341,9 +341,11 @@ static int to_wire(char *name)
if (*p >= 'A' && *p <= 'Z') if (*p >= 'A' && *p <= 'Z')
*p = *p - 'A' + 'a'; *p = *p - 'A' + 'a';
else if (*p == NAME_ESCAPE) else if (*p == NAME_ESCAPE)
for (q = p; *q; q++) {
for (q = p; *q; q++)
*q = *(q+1); *q = *(q+1);
(*p)--;
}
term = *p; term = *p;
if ((len = p - l) != 0) if ((len = p - l) != 0)
...@@ -376,7 +378,8 @@ static void from_wire(char *name) ...@@ -376,7 +378,8 @@ static void from_wire(char *name)
{ {
memmove(p+1, p, 1 + last - p); memmove(p+1, p, 1 + last - p);
len++; len++;
*p++ = NAME_ESCAPE; *p++ = NAME_ESCAPE;
(*p)++;
} }
l[len] = '.'; l[len] = '.';
......
...@@ -20,7 +20,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, ...@@ -20,7 +20,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
char *name, int isExtract, int extrabytes) char *name, int isExtract, int extrabytes)
{ {
unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL; unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL;
unsigned int j, l, hops = 0; unsigned int j, l, namelen = 0, hops = 0;
int retvalue = 1; int retvalue = 1;
if (isExtract) if (isExtract)
...@@ -94,9 +94,15 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, ...@@ -94,9 +94,15 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
count = 256; count = 256;
digs = ((count-1)>>2)+1; digs = ((count-1)>>2)+1;
/* output is \[x<hex>/siz]. which is digs+9 chars */ /* output is \[x<hex>/siz]. which is digs+6/7/8 chars */
if (cp - (unsigned char *)name + digs + 9 >= MAXDNAME) namelen += digs+6;
if (count > 9)
namelen++;
if (count > 99)
namelen++;
if (namelen+1 >= MAXDNAME)
return 0; return 0;
if (!CHECK_LEN(header, p, plen, (count-1)>>3)) if (!CHECK_LEN(header, p, plen, (count-1)>>3))
return 0; return 0;
...@@ -119,7 +125,8 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, ...@@ -119,7 +125,8 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
} }
else else
{ /* label_type = 0 -> label. */ { /* label_type = 0 -> label. */
if (cp - (unsigned char *)name + l + 1 >= MAXDNAME) namelen += l;
if (namelen+1 >= MAXDNAME)
return 0; return 0;
if (!CHECK_LEN(header, p, plen, l)) if (!CHECK_LEN(header, p, plen, l))
return 0; return 0;
...@@ -132,8 +139,12 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, ...@@ -132,8 +139,12 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
if (option_bool(OPT_DNSSEC_VALID)) if (option_bool(OPT_DNSSEC_VALID))
{ {
if (c == 0 || c == '.' || c == NAME_ESCAPE) if (c == 0 || c == '.' || c == NAME_ESCAPE)
*cp++ = NAME_ESCAPE; {
*cp++ = c; *cp++ = NAME_ESCAPE;
*cp++ = c+1;
}
else
*cp++ = c;
} }
else else
#endif #endif
...@@ -155,7 +166,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, ...@@ -155,7 +166,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
c1 += 'a' - 'A'; c1 += 'a' - 'A';
#ifdef HAVE_DNSSEC #ifdef HAVE_DNSSEC
if (option_bool(OPT_DNSSEC_VALID) && c1 == NAME_ESCAPE) if (option_bool(OPT_DNSSEC_VALID) && c1 == NAME_ESCAPE)
c1 = *cp++; c1 = (*cp++)-1;
#endif #endif
if (c2 >= 'A' && c2 <= 'Z') if (c2 >= 'A' && c2 <= 'Z')
......
...@@ -229,7 +229,7 @@ unsigned char *do_rfc1035_name(unsigned char *p, char *sval) ...@@ -229,7 +229,7 @@ unsigned char *do_rfc1035_name(unsigned char *p, char *sval)
{ {
#ifdef HAVE_DNSSEC #ifdef HAVE_DNSSEC
if (option_bool(OPT_DNSSEC_VALID) && *sval == NAME_ESCAPE) if (option_bool(OPT_DNSSEC_VALID) && *sval == NAME_ESCAPE)
*p++ = *(++sval); *p++ = (*(++sval))-1;
else else
#endif #endif
*p++ = *sval; *p++ = *sval;
......
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