From: Ondřej Surý Date: Tue, 10 Sep 2019 12:36:41 +0000 (+0200) Subject: Split dns_name_copy() into dns_name_copy() and dns_name_copynf() X-Git-Tag: v9.15.5~11^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7aef3738a9288d6b85bdc9ef4496ca1120acac7;p=thirdparty%2Fbind9.git Split dns_name_copy() into dns_name_copy() and dns_name_copynf() The dns_name_copy() function followed two different semanitcs that was driven whether the last argument was or wasn't NULL. This commit splits the function in two where now third argument to dns_name_copy() can't be NULL and dns_name_copynf() doesn't have third argument. --- diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index ae840785fbf..f25ecd5d9ba 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -1240,16 +1240,19 @@ dns_name_settotextfilter(dns_name_totextfilter_t proc); isc_result_t dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target); +void +dns_name_copynf(const dns_name_t *source, dns_name_t *dest); /*%< - * Makes 'dest' refer to a copy of the name in 'source'. The data are - * either copied to 'target' or the dedicated buffer in 'dest'. + * Makes 'dest' refer to a copy of the name in 'source'. The data are either + * copied to 'target' or in case of dns_name_copyfixed the dedicated buffer in + * 'dest'. * * Requires: * \li 'source' is a valid name. * * \li 'dest' is an initialized name with a dedicated buffer. * - * \li 'target' is NULL or an initialized buffer. + * \li 'target' is an initialized buffer. * * \li Either dest has a dedicated buffer or target != NULL. * diff --git a/lib/dns/name.c b/lib/dns/name.c index 12dafa8e2aa..2c021aad1f8 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -2443,50 +2443,46 @@ dns_name_fromstring2(dns_name_t *target, const char *src, return (result); } +static isc_result_t -dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) { +name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) { unsigned char *ndata; /* * Make dest a copy of source. */ - REQUIRE(VALID_NAME(source)); - REQUIRE(VALID_NAME(dest)); - REQUIRE(target != NULL || dest->buffer != NULL); - - if (target == NULL) { - target = dest->buffer; - isc_buffer_clear(dest->buffer); - } - REQUIRE(BINDABLE(dest)); /* * Set up. */ - if (target->length - target->used < source->length) + if (target->length - target->used < source->length) { return (ISC_R_NOSPACE); + } ndata = (unsigned char *)target->base + target->used; dest->ndata = target->base; - if (source->length != 0) + if (source->length != 0) { memmove(ndata, source->ndata, source->length); + } dest->ndata = ndata; dest->labels = source->labels; dest->length = source->length; - if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { dest->attributes = DNS_NAMEATTR_ABSOLUTE; - else + } else { dest->attributes = 0; + } if (dest->labels > 0 && dest->offsets != NULL) { - if (source->offsets != NULL) + if (source->offsets != NULL) { memmove(dest->offsets, source->offsets, source->labels); - else + } else { set_offsets(dest, dest->offsets, NULL); + } } isc_buffer_add(target, dest->length); @@ -2494,6 +2490,27 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) return (ISC_R_SUCCESS); } +isc_result_t +dns_name_copy(const dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) +{ + REQUIRE(VALID_NAME(source)); + REQUIRE(VALID_NAME(dest)); + REQUIRE(target != NULL); + + return (name_copy(source, dest, target)); +} + +void +dns_name_copynf(const dns_name_t *source, dns_name_t *dest) +{ + REQUIRE(VALID_NAME(source)); + REQUIRE(VALID_NAME(dest)); + REQUIRE(dest->buffer != NULL); + + isc_buffer_clear(dest->buffer); + RUNTIME_CHECK(name_copy(source, dest, dest->buffer) == ISC_R_SUCCESS); +} + void dns_name_destroy(void) { RUNTIME_CHECK(isc_once_do(&once, thread_key_mutex_init) diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index 99cbe11a6d7..44092edcef9 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -538,6 +538,7 @@ dns_name_clone dns_name_compare dns_name_concatenate dns_name_copy +dns_name_copynf dns_name_countlabels dns_name_destroy dns_name_digest