]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/lib/dns/rdata/generic/openpgpkey_61.c
Fix remote denial of service vulnerability when parsing malformed
[FreeBSD/stable/9.git] / contrib / bind9 / lib / dns / rdata / generic / openpgpkey_61.c
1 /*
2  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef RDATA_GENERIC_OPENPGPKEY_61_C
18 #define RDATA_GENERIC_OPENPGPKEY_61_C
19
20 #define RRTYPE_OPENPGPKEY_ATTRIBUTES 0
21
22 static inline isc_result_t
23 fromtext_openpgpkey(ARGS_FROMTEXT) {
24
25         REQUIRE(type == 61);
26
27         UNUSED(type);
28         UNUSED(rdclass);
29         UNUSED(callbacks);
30         UNUSED(options);
31         UNUSED(origin);
32
33         /*
34          * Keyring.
35          */
36         return (isc_base64_tobuffer(lexer, target, -1));
37 }
38
39 static inline isc_result_t
40 totext_openpgpkey(ARGS_TOTEXT) {
41         isc_region_t sr;
42
43         REQUIRE(rdata->type == 61);
44         REQUIRE(rdata->length != 0);
45
46         dns_rdata_toregion(rdata, &sr);
47
48         /*
49          * Keyring
50          */
51         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
52                 RETERR(str_totext("( ", target));
53         if (tctx->width == 0)   /* No splitting */
54                 RETERR(isc_base64_totext(&sr, 60, "", target));
55         else
56                 RETERR(isc_base64_totext(&sr, tctx->width - 2,
57                                          tctx->linebreak, target));
58         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
59                 RETERR(str_totext(" )", target));
60
61         return (ISC_R_SUCCESS);
62 }
63
64 static inline isc_result_t
65 fromwire_openpgpkey(ARGS_FROMWIRE) {
66         isc_region_t sr;
67
68         REQUIRE(type == 61);
69
70         UNUSED(type);
71         UNUSED(rdclass);
72         UNUSED(dctx);
73         UNUSED(options);
74
75         /*
76          * Keyring.
77          */
78         isc_buffer_activeregion(source, &sr);
79         if (sr.length < 1)
80                 return (ISC_R_UNEXPECTEDEND);
81         isc_buffer_forward(source, sr.length);
82         return (mem_tobuffer(target, sr.base, sr.length));
83 }
84
85 static inline isc_result_t
86 towire_openpgpkey(ARGS_TOWIRE) {
87         isc_region_t sr;
88
89         REQUIRE(rdata->type == 61);
90         REQUIRE(rdata->length != 0);
91
92         UNUSED(cctx);
93
94         dns_rdata_toregion(rdata, &sr);
95         return (mem_tobuffer(target, sr.base, sr.length));
96 }
97
98 static inline int
99 compare_openpgpkey(ARGS_COMPARE) {
100         isc_region_t r1;
101         isc_region_t r2;
102
103         REQUIRE(rdata1->type == rdata2->type);
104         REQUIRE(rdata1->rdclass == rdata2->rdclass);
105         REQUIRE(rdata1->type == 61);
106         REQUIRE(rdata1->length != 0);
107         REQUIRE(rdata2->length != 0);
108
109         dns_rdata_toregion(rdata1, &r1);
110         dns_rdata_toregion(rdata2, &r2);
111         return (isc_region_compare(&r1, &r2));
112 }
113
114 static inline isc_result_t
115 fromstruct_openpgpkey(ARGS_FROMSTRUCT) {
116         dns_rdata_openpgpkey_t *sig = source;
117
118         REQUIRE(type == 61);
119         REQUIRE(source != NULL);
120         REQUIRE(sig->common.rdtype == type);
121         REQUIRE(sig->common.rdclass == rdclass);
122         REQUIRE(sig->keyring != NULL && sig->length != 0);
123
124         UNUSED(type);
125         UNUSED(rdclass);
126
127         /*
128          * Keyring.
129          */
130         return (mem_tobuffer(target, sig->keyring, sig->length));
131 }
132
133 static inline isc_result_t
134 tostruct_openpgpkey(ARGS_TOSTRUCT) {
135         isc_region_t sr;
136         dns_rdata_openpgpkey_t *sig = target;
137
138         REQUIRE(rdata->type == 61);
139         REQUIRE(target != NULL);
140         REQUIRE(rdata->length != 0);
141
142         sig->common.rdclass = rdata->rdclass;
143         sig->common.rdtype = rdata->type;
144         ISC_LINK_INIT(&sig->common, link);
145
146         dns_rdata_toregion(rdata, &sr);
147
148         /*
149          * Keyring.
150          */
151         sig->length = sr.length;
152         sig->keyring = mem_maybedup(mctx, sr.base, sig->length);
153         if (sig->keyring == NULL)
154                 goto cleanup;
155
156         sig->mctx = mctx;
157         return (ISC_R_SUCCESS);
158
159  cleanup:
160         return (ISC_R_NOMEMORY);
161 }
162
163 static inline void
164 freestruct_openpgpkey(ARGS_FREESTRUCT) {
165         dns_rdata_openpgpkey_t *sig = (dns_rdata_openpgpkey_t *) source;
166
167         REQUIRE(source != NULL);
168         REQUIRE(sig->common.rdtype == 61);
169
170         if (sig->mctx == NULL)
171                 return;
172
173         if (sig->keyring != NULL)
174                 isc_mem_free(sig->mctx, sig->keyring);
175         sig->mctx = NULL;
176 }
177
178 static inline isc_result_t
179 additionaldata_openpgpkey(ARGS_ADDLDATA) {
180         REQUIRE(rdata->type == 61);
181
182         UNUSED(rdata);
183         UNUSED(add);
184         UNUSED(arg);
185
186         return (ISC_R_SUCCESS);
187 }
188
189 static inline isc_result_t
190 digest_openpgpkey(ARGS_DIGEST) {
191         isc_region_t r;
192
193         REQUIRE(rdata->type == 61);
194
195         dns_rdata_toregion(rdata, &r);
196
197         return ((digest)(arg, &r));
198 }
199
200 static inline isc_boolean_t
201 checkowner_openpgpkey(ARGS_CHECKOWNER) {
202
203         REQUIRE(type == 61);
204
205         UNUSED(name);
206         UNUSED(type);
207         UNUSED(rdclass);
208         UNUSED(wildcard);
209
210         return (ISC_TRUE);
211 }
212
213 static inline isc_boolean_t
214 checknames_openpgpkey(ARGS_CHECKNAMES) {
215
216         REQUIRE(rdata->type == 61);
217
218         UNUSED(rdata);
219         UNUSED(owner);
220         UNUSED(bad);
221
222         return (ISC_TRUE);
223 }
224
225 static inline int
226 casecompare_openpgpkey(ARGS_COMPARE) {
227         isc_region_t r1;
228         isc_region_t r2;
229
230         REQUIRE(rdata1->type == rdata2->type);
231         REQUIRE(rdata1->rdclass == rdata2->rdclass);
232         REQUIRE(rdata1->type == 61);
233         REQUIRE(rdata1->length != 0);
234         REQUIRE(rdata2->length != 0);
235
236         dns_rdata_toregion(rdata1, &r1);
237         dns_rdata_toregion(rdata2, &r2);
238
239         return (isc_region_compare(&r1, &r2));
240 }
241
242 #endif  /* RDATA_GENERIC_OPENPGPKEY_61_C */