mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Avoid unspecified behaviour in name_test
C does not make any guarantees about the value of padding in a structure, so bytewise comparison of two semantically equal structures with padding can be spuriously non-equal due to non-equal padding bytes. Compare each member of name.attributes individually to avoid this problem.
This commit is contained in:
@@ -500,11 +500,20 @@ ISC_RUN_TEST_IMPL(istat) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
name_attr_zero(struct dns_name_attrs attributes) {
|
||||
return (!(attributes.absolute | attributes.readonly |
|
||||
attributes.dynamic | attributes.dynoffsets |
|
||||
attributes.nocompress | attributes.cache | attributes.answer |
|
||||
attributes.ncache | attributes.chaining | attributes.chase |
|
||||
attributes.wildcard | attributes.prerequisite |
|
||||
attributes.update | attributes.hasupdaterec));
|
||||
}
|
||||
|
||||
/* dns_nane_init */
|
||||
ISC_RUN_TEST_IMPL(init) {
|
||||
dns_name_t name;
|
||||
unsigned char offsets[1];
|
||||
struct dns_name_attrs zeroes = {};
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
@@ -513,16 +522,15 @@ ISC_RUN_TEST_IMPL(init) {
|
||||
assert_null(name.ndata);
|
||||
assert_int_equal(name.length, 0);
|
||||
assert_int_equal(name.labels, 0);
|
||||
assert_memory_equal(&name.attributes, &zeroes, sizeof(zeroes));
|
||||
assert_ptr_equal(name.offsets, offsets);
|
||||
assert_null(name.buffer);
|
||||
assert_true(name_attr_zero(name.attributes));
|
||||
}
|
||||
|
||||
/* dns_nane_invalidate */
|
||||
ISC_RUN_TEST_IMPL(invalidate) {
|
||||
dns_name_t name;
|
||||
unsigned char offsets[1];
|
||||
struct dns_name_attrs zeroes = {};
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
@@ -532,9 +540,9 @@ ISC_RUN_TEST_IMPL(invalidate) {
|
||||
assert_null(name.ndata);
|
||||
assert_int_equal(name.length, 0);
|
||||
assert_int_equal(name.labels, 0);
|
||||
assert_memory_equal(&name.attributes, &zeroes, sizeof(zeroes));
|
||||
assert_null(name.offsets);
|
||||
assert_null(name.buffer);
|
||||
assert_true(name_attr_zero(name.attributes));
|
||||
}
|
||||
|
||||
/* dns_nane_setbuffer/hasbuffer */
|
||||
|
Reference in New Issue
Block a user