]>
Commit | Line | Data |
---|---|---|
6ac0a1a3 MT |
1 | From b8f16556d36924cd8dc7663cb4129d7b1f3fc2be Mon Sep 17 00:00:00 2001 |
2 | From: Simon Kelley <simon@thekelleys.org.uk> | |
3 | Date: Wed, 22 Apr 2015 21:14:31 +0100 | |
697b4f04 | 4 | Subject: [PATCH 082/113] Tweaks to previous, DNS label charset commit. |
6ac0a1a3 MT |
5 | |
6 | --- | |
7 | src/dns-protocol.h | 6 +++++- | |
8 | src/dnssec.c | 9 ++++++--- | |
9 | src/rfc1035.c | 25 ++++++++++++++++++------- | |
10 | src/util.c | 2 +- | |
11 | 4 files changed, 30 insertions(+), 12 deletions(-) | |
12 | ||
13 | diff --git a/src/dns-protocol.h b/src/dns-protocol.h | |
14 | index 7f5d686bb150..4b71746f8d26 100644 | |
15 | --- a/src/dns-protocol.h | |
16 | +++ b/src/dns-protocol.h | |
17 | @@ -144,5 +144,9 @@ struct dns_header { | |
18 | (!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1)) | |
19 | ||
20 | /* Escape character in our presentation format for names. | |
21 | - Cannot be '.' or /000 and must be !isprint() */ | |
22 | + Cannot be '.' or /000 and must be !isprint(). | |
23 | + Note that escaped chars are stored as | |
24 | + <NAME_ESCAPE> <orig-char+1> | |
25 | + to ensure that the escaped form of /000 doesn't include /000 | |
26 | +*/ | |
27 | #define NAME_ESCAPE 1 | |
28 | diff --git a/src/dnssec.c b/src/dnssec.c | |
29 | index c116a7b5f6f4..a9e12153ccf2 100644 | |
30 | --- a/src/dnssec.c | |
31 | +++ b/src/dnssec.c | |
32 | @@ -341,9 +341,11 @@ static int to_wire(char *name) | |
33 | if (*p >= 'A' && *p <= 'Z') | |
34 | *p = *p - 'A' + 'a'; | |
35 | else if (*p == NAME_ESCAPE) | |
36 | - for (q = p; *q; q++) | |
37 | + { | |
38 | + for (q = p; *q; q++) | |
39 | *q = *(q+1); | |
40 | - | |
41 | + (*p)--; | |
42 | + } | |
43 | term = *p; | |
44 | ||
45 | if ((len = p - l) != 0) | |
46 | @@ -376,7 +378,8 @@ static void from_wire(char *name) | |
47 | { | |
48 | memmove(p+1, p, 1 + last - p); | |
49 | len++; | |
50 | - *p++ = NAME_ESCAPE; | |
51 | + *p++ = NAME_ESCAPE; | |
52 | + (*p)++; | |
53 | } | |
54 | ||
55 | l[len] = '.'; | |
56 | diff --git a/src/rfc1035.c b/src/rfc1035.c | |
57 | index 19fecc818c06..32df31ad603c 100644 | |
58 | --- a/src/rfc1035.c | |
59 | +++ b/src/rfc1035.c | |
60 | @@ -20,7 +20,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, | |
61 | char *name, int isExtract, int extrabytes) | |
62 | { | |
63 | unsigned char *cp = (unsigned char *)name, *p = *pp, *p1 = NULL; | |
64 | - unsigned int j, l, hops = 0; | |
65 | + unsigned int j, l, namelen = 0, hops = 0; | |
66 | int retvalue = 1; | |
67 | ||
68 | if (isExtract) | |
69 | @@ -94,9 +94,15 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, | |
70 | count = 256; | |
71 | digs = ((count-1)>>2)+1; | |
72 | ||
73 | - /* output is \[x<hex>/siz]. which is digs+9 chars */ | |
74 | - if (cp - (unsigned char *)name + digs + 9 >= MAXDNAME) | |
75 | + /* output is \[x<hex>/siz]. which is digs+6/7/8 chars */ | |
76 | + namelen += digs+6; | |
77 | + if (count > 9) | |
78 | + namelen++; | |
79 | + if (count > 99) | |
80 | + namelen++; | |
81 | + if (namelen+1 >= MAXDNAME) | |
82 | return 0; | |
83 | + | |
84 | if (!CHECK_LEN(header, p, plen, (count-1)>>3)) | |
85 | return 0; | |
86 | ||
87 | @@ -119,7 +125,8 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, | |
88 | } | |
89 | else | |
90 | { /* label_type = 0 -> label. */ | |
91 | - if (cp - (unsigned char *)name + l + 1 >= MAXDNAME) | |
92 | + namelen += l; | |
93 | + if (namelen+1 >= MAXDNAME) | |
94 | return 0; | |
95 | if (!CHECK_LEN(header, p, plen, l)) | |
96 | return 0; | |
97 | @@ -132,8 +139,12 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, | |
98 | if (option_bool(OPT_DNSSEC_VALID)) | |
99 | { | |
100 | if (c == 0 || c == '.' || c == NAME_ESCAPE) | |
101 | - *cp++ = NAME_ESCAPE; | |
102 | - *cp++ = c; | |
103 | + { | |
104 | + *cp++ = NAME_ESCAPE; | |
105 | + *cp++ = c+1; | |
106 | + } | |
107 | + else | |
108 | + *cp++ = c; | |
109 | } | |
110 | else | |
111 | #endif | |
112 | @@ -155,7 +166,7 @@ int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, | |
113 | c1 += 'a' - 'A'; | |
114 | #ifdef HAVE_DNSSEC | |
115 | if (option_bool(OPT_DNSSEC_VALID) && c1 == NAME_ESCAPE) | |
116 | - c1 = *cp++; | |
117 | + c1 = (*cp++)-1; | |
118 | #endif | |
119 | ||
120 | if (c2 >= 'A' && c2 <= 'Z') | |
121 | diff --git a/src/util.c b/src/util.c | |
122 | index 0c1a48b4700a..9299703c6d30 100644 | |
123 | --- a/src/util.c | |
124 | +++ b/src/util.c | |
125 | @@ -229,7 +229,7 @@ unsigned char *do_rfc1035_name(unsigned char *p, char *sval) | |
126 | { | |
127 | #ifdef HAVE_DNSSEC | |
128 | if (option_bool(OPT_DNSSEC_VALID) && *sval == NAME_ESCAPE) | |
129 | - *p++ = *(++sval); | |
130 | + *p++ = (*(++sval))-1; | |
131 | else | |
132 | #endif | |
133 | *p++ = *sval; | |
134 | -- | |
135 | 2.1.0 | |
136 |