2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00

Remove MAKE_EMPTY() macro from dns_name unit

The MAKE_EMPTY() macro was clearing up the output variable in case of
the failure.  However, this was breaking the usual design pattern that
the output variables are left in indeterminate state or we don't touch
them at all when a failure occurs.  Remove the macro and change the
dns_name_downcase() to not touch the name contents until success.
This commit is contained in:
Ondřej Surý 2025-02-24 13:58:13 +01:00
parent 259600c837
commit 3bb47bc6cd
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41

View File

@ -46,17 +46,6 @@ typedef enum {
ft_at
} ft_state;
/*%
* Note: If additional attributes are added that should not be set for
* empty names, MAKE_EMPTY() must be changed so it clears them.
*/
#define MAKE_EMPTY(name) \
{ \
name->ndata = NULL; \
name->length = 0; \
name->attributes.absolute = false; \
}
/*%
* Note that the name data must be a char array, not a string
* literal, to avoid compiler warnings about discarding
@ -743,11 +732,6 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
REQUIRE(DNS_NAME_BINDABLE(name));
/*
* Make 'name' empty in case of failure.
*/
MAKE_EMPTY(name);
/*
* Set up the state machine.
*/
@ -1256,6 +1240,7 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
REQUIRE(DNS_NAME_VALID(source));
REQUIRE(DNS_NAME_VALID(name));
if (source == name) {
REQUIRE(!name->attributes.readonly);
isc_buffer_init(&buffer, source->ndata, source->length);
@ -1266,18 +1251,18 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
if (target == NULL) {
if (source->length > name->buffer->length) {
return ISC_R_NOSPACE;
}
target = name->buffer;
isc_buffer_clear(name->buffer);
} else if (source->length > target->length - target->used) {
return ISC_R_NOSPACE;
}
ndata = (unsigned char *)target->base + target->used;
name->ndata = ndata;
}
if (source->length > (target->length - target->used)) {
MAKE_EMPTY(name);
return ISC_R_NOSPACE;
}
/* label lengths are < 64 so tolower() does not affect them */
isc_ascii_lowercopy(ndata, source->ndata, source->length);
@ -1400,7 +1385,6 @@ dns_name_fromwire(dns_name_t *const name, isc_buffer_t *const source,
const uint32_t name_max = ISC_MIN(DNS_NAME_MAXWIRE,
isc_buffer_availablelength(target));
uint32_t name_len = 0;
MAKE_EMPTY(name); /* in case of failure */
/*
* After chasing a compression pointer, these variables refer to the
@ -1628,11 +1612,9 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
length += suffix->length;
}
if (length > DNS_NAME_MAXWIRE) {
MAKE_EMPTY(name);
return DNS_R_NAMETOOLONG;
}
if (length > nrem) {
MAKE_EMPTY(name);
return ISC_R_NOSPACE;
}
@ -1672,11 +1654,6 @@ dns_name_dup(const dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
REQUIRE(DNS_NAME_VALID(target));
REQUIRE(DNS_NAME_BINDABLE(target));
/*
* Make 'target' empty in case of failure.
*/
MAKE_EMPTY(target);
target->ndata = isc_mem_get(mctx, source->length);
memmove(target->ndata, source->ndata, source->length);