]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - contrib/bind9/lib/dns/diff.c
Fix BIND remote denial of service vulnerability. [SA-15:27]
[FreeBSD/releng/9.3.git] / contrib / bind9 / lib / dns / diff.c
1 /*
2  * Copyright (C) 2004, 2005, 2007-2009, 2011, 2013, 2014  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: diff.c,v 1.26 2011/03/25 23:53:02 each Exp $ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <stdlib.h>
25
26 #include <isc/buffer.h>
27 #include <isc/file.h>
28 #include <isc/mem.h>
29 #include <isc/string.h>
30 #include <isc/util.h>
31
32 #include <dns/db.h>
33 #include <dns/diff.h>
34 #include <dns/log.h>
35 #include <dns/rdataclass.h>
36 #include <dns/rdatalist.h>
37 #include <dns/rdataset.h>
38 #include <dns/rdatastruct.h>
39 #include <dns/rdatatype.h>
40 #include <dns/result.h>
41
42 #define CHECK(op) \
43         do { result = (op);                                     \
44                 if (result != ISC_R_SUCCESS) goto failure;      \
45         } while (0)
46
47 #define DIFF_COMMON_LOGARGS \
48         dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DIFF
49
50 static dns_rdatatype_t
51 rdata_covers(dns_rdata_t *rdata) {
52         return (rdata->type == dns_rdatatype_rrsig ?
53                 dns_rdata_covers(rdata) : 0);
54 }
55
56 isc_result_t
57 dns_difftuple_create(isc_mem_t *mctx,
58                      dns_diffop_t op, dns_name_t *name, dns_ttl_t ttl,
59                      dns_rdata_t *rdata, dns_difftuple_t **tp)
60 {
61         dns_difftuple_t *t;
62         unsigned int size;
63         unsigned char *datap;
64
65         REQUIRE(tp != NULL && *tp == NULL);
66
67         /*
68          * Create a new tuple.  The variable-size wire-format name data and
69          * rdata immediately follow the dns_difftuple_t structure
70          * in memory.
71          */
72         size = sizeof(*t) + name->length + rdata->length;
73         t = isc_mem_allocate(mctx, size);
74         if (t == NULL)
75                 return (ISC_R_NOMEMORY);
76         t->mctx = NULL;
77         isc_mem_attach(mctx, &t->mctx);
78         t->op = op;
79
80         datap = (unsigned char *)(t + 1);
81
82         memmove(datap, name->ndata, name->length);
83         dns_name_init(&t->name, NULL);
84         dns_name_clone(name, &t->name);
85         t->name.ndata = datap;
86         datap += name->length;
87
88         t->ttl = ttl;
89
90         memmove(datap, rdata->data, rdata->length);
91         dns_rdata_init(&t->rdata);
92         dns_rdata_clone(rdata, &t->rdata);
93         t->rdata.data = datap;
94         datap += rdata->length;
95
96         ISC_LINK_INIT(&t->rdata, link);
97         ISC_LINK_INIT(t, link);
98         t->magic = DNS_DIFFTUPLE_MAGIC;
99
100         INSIST(datap == (unsigned char *)t + size);
101
102         *tp = t;
103         return (ISC_R_SUCCESS);
104 }
105
106 void
107 dns_difftuple_free(dns_difftuple_t **tp) {
108         dns_difftuple_t *t = *tp;
109         isc_mem_t *mctx;
110
111         REQUIRE(DNS_DIFFTUPLE_VALID(t));
112
113         dns_name_invalidate(&t->name);
114         t->magic = 0;
115         mctx = t->mctx;
116         isc_mem_free(mctx, t);
117         isc_mem_detach(&mctx);
118         *tp = NULL;
119 }
120
121 isc_result_t
122 dns_difftuple_copy(dns_difftuple_t *orig, dns_difftuple_t **copyp) {
123         return (dns_difftuple_create(orig->mctx, orig->op, &orig->name,
124                                      orig->ttl, &orig->rdata, copyp));
125 }
126
127 void
128 dns_diff_init(isc_mem_t *mctx, dns_diff_t *diff) {
129         diff->mctx = mctx;
130         diff->resign = 0;
131         ISC_LIST_INIT(diff->tuples);
132         diff->magic = DNS_DIFF_MAGIC;
133 }
134
135 void
136 dns_diff_clear(dns_diff_t *diff) {
137         dns_difftuple_t *t;
138         REQUIRE(DNS_DIFF_VALID(diff));
139         while ((t = ISC_LIST_HEAD(diff->tuples)) != NULL) {
140                 ISC_LIST_UNLINK(diff->tuples, t, link);
141                 dns_difftuple_free(&t);
142         }
143         ENSURE(ISC_LIST_EMPTY(diff->tuples));
144 }
145
146 void
147 dns_diff_append(dns_diff_t *diff, dns_difftuple_t **tuplep)
148 {
149         ISC_LIST_APPEND(diff->tuples, *tuplep, link);
150         *tuplep = NULL;
151 }
152
153 /* XXX this is O(N) */
154
155 void
156 dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep)
157 {
158         dns_difftuple_t *ot, *next_ot;
159
160         REQUIRE(DNS_DIFF_VALID(diff));
161         REQUIRE(DNS_DIFFTUPLE_VALID(*tuplep));
162
163         /*
164          * Look for an existing tuple with the same owner name,
165          * rdata, and TTL.   If we are doing an addition and find a
166          * deletion or vice versa, remove both the old and the
167          * new tuple since they cancel each other out (assuming
168          * that we never delete nonexistent data or add existing
169          * data).
170          *
171          * If we find an old update of the same kind as
172          * the one we are doing, there must be a programming
173          * error.  We report it but try to continue anyway.
174          */
175         for (ot = ISC_LIST_HEAD(diff->tuples); ot != NULL;
176              ot = next_ot)
177         {
178                 next_ot = ISC_LIST_NEXT(ot, link);
179                 if (dns_name_equal(&ot->name, &(*tuplep)->name) &&
180                     dns_rdata_compare(&ot->rdata, &(*tuplep)->rdata) == 0 &&
181                     ot->ttl == (*tuplep)->ttl)
182                 {
183                         ISC_LIST_UNLINK(diff->tuples, ot, link);
184                         if ((*tuplep)->op == ot->op) {
185                                 UNEXPECTED_ERROR(__FILE__, __LINE__,
186                                          "unexpected non-minimal diff");
187                         } else {
188                                 dns_difftuple_free(tuplep);
189                         }
190                         dns_difftuple_free(&ot);
191                         break;
192                 }
193         }
194
195         if (*tuplep != NULL) {
196                 ISC_LIST_APPEND(diff->tuples, *tuplep, link);
197                 *tuplep = NULL;
198         }
199
200         ENSURE(*tuplep == NULL);
201 }
202
203 static isc_stdtime_t
204 setresign(dns_rdataset_t *modified, isc_uint32_t delta) {
205         dns_rdata_t rdata = DNS_RDATA_INIT;
206         dns_rdata_rrsig_t sig;
207         isc_stdtime_t when;
208         isc_result_t result;
209
210         result = dns_rdataset_first(modified);
211         INSIST(result == ISC_R_SUCCESS);
212         dns_rdataset_current(modified, &rdata);
213         (void)dns_rdata_tostruct(&rdata, &sig, NULL);
214         if ((rdata.flags & DNS_RDATA_OFFLINE) != 0)
215                 when = 0;
216         else
217                 when = sig.timeexpire - delta;
218         dns_rdata_reset(&rdata);
219
220         result = dns_rdataset_next(modified);
221         while (result == ISC_R_SUCCESS) {
222                 dns_rdataset_current(modified, &rdata);
223                 (void)dns_rdata_tostruct(&rdata, &sig, NULL);
224                 if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) {
225                         goto next_rr;
226                 }
227                 if (when == 0 || sig.timeexpire - delta < when)
228                         when = sig.timeexpire - delta;
229  next_rr:
230                 dns_rdata_reset(&rdata);
231                 result = dns_rdataset_next(modified);
232         }
233         INSIST(result == ISC_R_NOMORE);
234         return (when);
235 }
236
237 static isc_result_t
238 diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver,
239            isc_boolean_t warn)
240 {
241         dns_difftuple_t *t;
242         dns_dbnode_t *node = NULL;
243         isc_result_t result;
244         char namebuf[DNS_NAME_FORMATSIZE];
245         char typebuf[DNS_RDATATYPE_FORMATSIZE];
246         char classbuf[DNS_RDATACLASS_FORMATSIZE];
247
248         REQUIRE(DNS_DIFF_VALID(diff));
249         REQUIRE(DNS_DB_VALID(db));
250
251         t = ISC_LIST_HEAD(diff->tuples);
252         while (t != NULL) {
253                 dns_name_t *name;
254
255                 INSIST(node == NULL);
256                 name = &t->name;
257                 /*
258                  * Find the node.
259                  * We create the node if it does not exist.
260                  * This will cause an empty node to be created if the diff
261                  * contains a deletion of an RR at a nonexistent name,
262                  * but such diffs should never be created in the first
263                  * place.
264                  */
265
266                 while (t != NULL && dns_name_equal(&t->name, name)) {
267                         dns_rdatatype_t type, covers;
268                         dns_diffop_t op;
269                         dns_rdatalist_t rdl;
270                         dns_rdataset_t rds;
271                         dns_rdataset_t ardataset;
272                         dns_rdataset_t *modified = NULL;
273
274                         op = t->op;
275                         type = t->rdata.type;
276                         covers = rdata_covers(&t->rdata);
277
278                         /*
279                          * Collect a contiguous set of updates with
280                          * the same operation (add/delete) and RR type
281                          * into a single rdatalist so that the
282                          * database rrset merging/subtraction code
283                          * can work more efficiently than if each
284                          * RR were merged into / subtracted from
285                          * the database separately.
286                          *
287                          * This is done by linking rdata structures from the
288                          * diff into "rdatalist".  This uses the rdata link
289                          * field, not the diff link field, so the structure
290                          * of the diff itself is not affected.
291                          */
292
293                         rdl.type = type;
294                         rdl.covers = covers;
295                         rdl.rdclass = t->rdata.rdclass;
296                         rdl.ttl = t->ttl;
297                         ISC_LIST_INIT(rdl.rdata);
298                         ISC_LINK_INIT(&rdl, link);
299
300                         node = NULL;
301                         if (type != dns_rdatatype_nsec3 &&
302                             covers != dns_rdatatype_nsec3)
303                                 CHECK(dns_db_findnode(db, name, ISC_TRUE,
304                                                       &node));
305                         else
306                                 CHECK(dns_db_findnsec3node(db, name, ISC_TRUE,
307                                                            &node));
308
309                         while (t != NULL &&
310                                dns_name_equal(&t->name, name) &&
311                                t->op == op &&
312                                t->rdata.type == type &&
313                                rdata_covers(&t->rdata) == covers)
314                         {
315                                 dns_name_format(name, namebuf, sizeof(namebuf));
316                                 dns_rdatatype_format(t->rdata.type, typebuf,
317                                                      sizeof(typebuf));
318                                 dns_rdataclass_format(t->rdata.rdclass,
319                                                       classbuf,
320                                                       sizeof(classbuf));
321                                 if (t->ttl != rdl.ttl && warn)
322                                         isc_log_write(DIFF_COMMON_LOGARGS,
323                                                 ISC_LOG_WARNING,
324                                                 "'%s/%s/%s': TTL differs in "
325                                                 "rdataset, adjusting "
326                                                 "%lu -> %lu",
327                                                 namebuf, typebuf, classbuf,
328                                                 (unsigned long) t->ttl,
329                                                 (unsigned long) rdl.ttl);
330                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
331                                 t = ISC_LIST_NEXT(t, link);
332                         }
333
334                         /*
335                          * Convert the rdatalist into a rdataset.
336                          */
337                         dns_rdataset_init(&rds);
338                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
339                         if (rds.type == dns_rdatatype_rrsig)
340                                 switch (op) {
341                                 case DNS_DIFFOP_ADDRESIGN:
342                                 case DNS_DIFFOP_DELRESIGN:
343                                         modified = &ardataset;
344                                         dns_rdataset_init(modified);
345                                         break;
346                                 default:
347                                         break;
348                                 }
349                         rds.trust = dns_trust_ultimate;
350
351                         /*
352                          * Merge the rdataset into the database.
353                          */
354                         switch (op) {
355                         case DNS_DIFFOP_ADD:
356                         case DNS_DIFFOP_ADDRESIGN:
357                                 result = dns_db_addrdataset(db, node, ver,
358                                                             0, &rds,
359                                                             DNS_DBADD_MERGE|
360                                                             DNS_DBADD_EXACT|
361                                                             DNS_DBADD_EXACTTTL,
362                                                             modified);
363                                 break;
364                         case DNS_DIFFOP_DEL:
365                         case DNS_DIFFOP_DELRESIGN:
366                                 result = dns_db_subtractrdataset(db, node, ver,
367                                                                &rds,
368                                                                DNS_DBSUB_EXACT,
369                                                                modified);
370                                 break;
371                         default:
372                                 INSIST(0);
373                         }
374
375                         if (result == ISC_R_SUCCESS) {
376                                 if (modified != NULL) {
377                                         isc_stdtime_t resign;
378                                         resign = setresign(modified,
379                                                            diff->resign);
380                                         dns_db_setsigningtime(db, modified,
381                                                               resign);
382                                 }
383                         } else if (result == DNS_R_UNCHANGED) {
384                                 /*
385                                  * This will not happen when executing a
386                                  * dynamic update, because that code will
387                                  * generate strictly minimal diffs.
388                                  * It may happen when receiving an IXFR
389                                  * from a server that is not as careful.
390                                  * Issue a warning and continue.
391                                  */
392                                 if (warn) {
393                                         char classbuf[DNS_RDATATYPE_FORMATSIZE];
394                                         char namebuf[DNS_NAME_FORMATSIZE];
395
396                                         dns_name_format(dns_db_origin(db),
397                                                         namebuf,
398                                                         sizeof(namebuf));
399                                         dns_rdataclass_format(dns_db_class(db),
400                                                               classbuf,
401                                                               sizeof(classbuf));
402                                         isc_log_write(DIFF_COMMON_LOGARGS,
403                                                       ISC_LOG_WARNING,
404                                                       "%s/%s: dns_diff_apply: "
405                                                       "update with no effect",
406                                                       namebuf, classbuf);
407                                 }
408                         } else if (result == DNS_R_NXRRSET) {
409                                 /*
410                                  * OK.
411                                  */
412                         } else {
413                                 if (modified != NULL &&
414                                     dns_rdataset_isassociated(modified))
415                                         dns_rdataset_disassociate(modified);
416                                 CHECK(result);
417                         }
418                         dns_db_detachnode(db, &node);
419                         if (modified != NULL &&
420                             dns_rdataset_isassociated(modified))
421                                 dns_rdataset_disassociate(modified);
422                 }
423         }
424         return (ISC_R_SUCCESS);
425
426  failure:
427         if (node != NULL)
428                 dns_db_detachnode(db, &node);
429         return (result);
430 }
431
432 isc_result_t
433 dns_diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
434         return (diff_apply(diff, db, ver, ISC_TRUE));
435 }
436
437 isc_result_t
438 dns_diff_applysilently(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver) {
439         return (diff_apply(diff, db, ver, ISC_FALSE));
440 }
441
442 /* XXX this duplicates lots of code in diff_apply(). */
443
444 isc_result_t
445 dns_diff_load(dns_diff_t *diff, dns_addrdatasetfunc_t addfunc,
446               void *add_private)
447 {
448         dns_difftuple_t *t;
449         isc_result_t result;
450
451         REQUIRE(DNS_DIFF_VALID(diff));
452
453         t = ISC_LIST_HEAD(diff->tuples);
454         while (t != NULL) {
455                 dns_name_t *name;
456
457                 name = &t->name;
458                 while (t != NULL && dns_name_equal(&t->name, name)) {
459                         dns_rdatatype_t type, covers;
460                         dns_diffop_t op;
461                         dns_rdatalist_t rdl;
462                         dns_rdataset_t rds;
463
464                         op = t->op;
465                         type = t->rdata.type;
466                         covers = rdata_covers(&t->rdata);
467
468                         rdl.type = type;
469                         rdl.covers = covers;
470                         rdl.rdclass = t->rdata.rdclass;
471                         rdl.ttl = t->ttl;
472                         ISC_LIST_INIT(rdl.rdata);
473                         ISC_LINK_INIT(&rdl, link);
474
475                         while (t != NULL && dns_name_equal(&t->name, name) &&
476                                t->op == op && t->rdata.type == type &&
477                                rdata_covers(&t->rdata) == covers)
478                         {
479                                 ISC_LIST_APPEND(rdl.rdata, &t->rdata, link);
480                                 t = ISC_LIST_NEXT(t, link);
481                         }
482
483                         /*
484                          * Convert the rdatalist into a rdataset.
485                          */
486                         dns_rdataset_init(&rds);
487                         CHECK(dns_rdatalist_tordataset(&rdl, &rds));
488                         rds.trust = dns_trust_ultimate;
489
490                         INSIST(op == DNS_DIFFOP_ADD);
491                         result = (*addfunc)(add_private, name, &rds);
492                         if (result == DNS_R_UNCHANGED) {
493                                 isc_log_write(DIFF_COMMON_LOGARGS,
494                                               ISC_LOG_WARNING,
495                                               "dns_diff_load: "
496                                               "update with no effect");
497                         } else if (result == ISC_R_SUCCESS ||
498                                    result == DNS_R_NXRRSET) {
499                                 /*
500                                  * OK.
501                                  */
502                         } else {
503                                 CHECK(result);
504                         }
505                 }
506         }
507         result = ISC_R_SUCCESS;
508  failure:
509         return (result);
510 }
511
512 /*
513  * XXX uses qsort(); a merge sort would be more natural for lists,
514  * and perhaps safer wrt thread stack overflow.
515  */
516 isc_result_t
517 dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) {
518         unsigned int length = 0;
519         unsigned int i;
520         dns_difftuple_t **v;
521         dns_difftuple_t *p;
522         REQUIRE(DNS_DIFF_VALID(diff));
523
524         for (p = ISC_LIST_HEAD(diff->tuples);
525              p != NULL;
526              p = ISC_LIST_NEXT(p, link))
527                 length++;
528         if (length == 0)
529                 return (ISC_R_SUCCESS);
530         v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *));
531         if (v == NULL)
532                 return (ISC_R_NOMEMORY);
533         for (i = 0; i < length; i++) {
534                 p = ISC_LIST_HEAD(diff->tuples);
535                 v[i] = p;
536                 ISC_LIST_UNLINK(diff->tuples, p, link);
537         }
538         INSIST(ISC_LIST_HEAD(diff->tuples) == NULL);
539         qsort(v, length, sizeof(v[0]), compare);
540         for (i = 0; i < length; i++) {
541                 ISC_LIST_APPEND(diff->tuples, v[i], link);
542         }
543         isc_mem_put(diff->mctx, v, length * sizeof(dns_difftuple_t *));
544         return (ISC_R_SUCCESS);
545 }
546
547
548 /*
549  * Create an rdataset containing the single RR of the given
550  * tuple.  The caller must allocate the rdata, rdataset and
551  * an rdatalist structure for it to refer to.
552  */
553
554 static isc_result_t
555 diff_tuple_tordataset(dns_difftuple_t *t, dns_rdata_t *rdata,
556                       dns_rdatalist_t *rdl, dns_rdataset_t *rds)
557 {
558         REQUIRE(DNS_DIFFTUPLE_VALID(t));
559         REQUIRE(rdl != NULL);
560         REQUIRE(rds != NULL);
561
562         rdl->type = t->rdata.type;
563         rdl->rdclass = t->rdata.rdclass;
564         rdl->ttl = t->ttl;
565         ISC_LIST_INIT(rdl->rdata);
566         ISC_LINK_INIT(rdl, link);
567         dns_rdataset_init(rds);
568         ISC_LINK_INIT(rdata, link);
569         dns_rdata_clone(&t->rdata, rdata);
570         ISC_LIST_APPEND(rdl->rdata, rdata, link);
571         return (dns_rdatalist_tordataset(rdl, rds));
572 }
573
574 isc_result_t
575 dns_diff_print(dns_diff_t *diff, FILE *file) {
576         isc_result_t result;
577         dns_difftuple_t *t;
578         char *mem = NULL;
579         unsigned int size = 2048;
580         const char *op = NULL;
581
582         REQUIRE(DNS_DIFF_VALID(diff));
583
584         mem = isc_mem_get(diff->mctx, size);
585         if (mem == NULL)
586                 return (ISC_R_NOMEMORY);
587
588         for (t = ISC_LIST_HEAD(diff->tuples); t != NULL;
589              t = ISC_LIST_NEXT(t, link))
590         {
591                 isc_buffer_t buf;
592                 isc_region_t r;
593
594                 dns_rdatalist_t rdl;
595                 dns_rdataset_t rds;
596                 dns_rdata_t rd = DNS_RDATA_INIT;
597
598                 result = diff_tuple_tordataset(t, &rd, &rdl, &rds);
599                 if (result != ISC_R_SUCCESS) {
600                         UNEXPECTED_ERROR(__FILE__, __LINE__,
601                                          "diff_tuple_tordataset failed: %s",
602                                          dns_result_totext(result));
603                         result =  ISC_R_UNEXPECTED;
604                         goto cleanup;
605                 }
606  again:
607                 isc_buffer_init(&buf, mem, size);
608                 result = dns_rdataset_totext(&rds, &t->name,
609                                              ISC_FALSE, ISC_FALSE, &buf);
610
611                 if (result == ISC_R_NOSPACE) {
612                         isc_mem_put(diff->mctx, mem, size);
613                         size += 1024;
614                         mem = isc_mem_get(diff->mctx, size);
615                         if (mem == NULL) {
616                                 result = ISC_R_NOMEMORY;
617                                 goto cleanup;
618                         }
619                         goto again;
620                 }
621
622                 if (result != ISC_R_SUCCESS)
623                         goto cleanup;
624                 /*
625                  * Get rid of final newline.
626                  */
627                 INSIST(buf.used >= 1 &&
628                        ((char *) buf.base)[buf.used-1] == '\n');
629                 buf.used--;
630
631                 isc_buffer_usedregion(&buf, &r);
632                 switch (t->op) {
633                 case DNS_DIFFOP_EXISTS: op = "exists"; break;
634                 case DNS_DIFFOP_ADD: op = "add"; break;
635                 case DNS_DIFFOP_DEL: op = "del"; break;
636                 case DNS_DIFFOP_ADDRESIGN: op = "add re-sign"; break;
637                 case DNS_DIFFOP_DELRESIGN: op = "del re-sign"; break;
638                 }
639                 if (file != NULL)
640                         fprintf(file, "%s %.*s\n", op, (int) r.length,
641                                 (char *) r.base);
642                 else
643                         isc_log_write(DIFF_COMMON_LOGARGS, ISC_LOG_DEBUG(7),
644                                       "%s %.*s", op, (int) r.length,
645                                       (char *) r.base);
646         }
647         result = ISC_R_SUCCESS;
648  cleanup:
649         if (mem != NULL)
650                 isc_mem_put(diff->mctx, mem, size);
651         return (result);
652 }