mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
Fix the assertion failure when putting 48-bit number to buffer
When putting the 48-bit number into a fixed-size buffer that's exactly 6 bytes, the assertion failure would occur as the 48-bit number is internally represented as 64-bit number and the code was checking if there is enough space for `sizeof(val)`. This causes assertion failure when otherwise valid TSIG signature has a bad timing information. Specify the size of the argument explicitly, so the 48-bit number doesn't require 8-byte long buffer.
This commit is contained in:
parent
026024a6ae
commit
37dbd57c16
@ -857,22 +857,21 @@ isc_buffer_getuint8(isc_buffer_t *restrict b) {
|
||||
return (val);
|
||||
}
|
||||
|
||||
#define ISC_BUFFER_PUT_RESERVE(b, v) \
|
||||
{ \
|
||||
REQUIRE(ISC_BUFFER_VALID(b)); \
|
||||
\
|
||||
if (b->mctx) { \
|
||||
isc_result_t result = isc_buffer_reserve(b, \
|
||||
sizeof(val)); \
|
||||
ENSURE(result == ISC_R_SUCCESS); \
|
||||
} \
|
||||
\
|
||||
REQUIRE(isc_buffer_availablelength(b) >= sizeof(val)); \
|
||||
#define ISC_BUFFER_PUT_RESERVE(b, v, s) \
|
||||
{ \
|
||||
REQUIRE(ISC_BUFFER_VALID(b)); \
|
||||
\
|
||||
if (b->mctx) { \
|
||||
isc_result_t result = isc_buffer_reserve(b, s); \
|
||||
ENSURE(result == ISC_R_SUCCESS); \
|
||||
} \
|
||||
\
|
||||
REQUIRE(isc_buffer_availablelength(b) >= s); \
|
||||
}
|
||||
|
||||
static inline void
|
||||
isc_buffer_putuint8(isc_buffer_t *restrict b, const uint8_t val) {
|
||||
ISC_BUFFER_PUT_RESERVE(b, val);
|
||||
ISC_BUFFER_PUT_RESERVE(b, val, sizeof(val));
|
||||
|
||||
uint8_t *cp = isc_buffer_used(b);
|
||||
b->used += sizeof(val);
|
||||
@ -900,7 +899,7 @@ isc_buffer_getuint16(isc_buffer_t *restrict b) {
|
||||
|
||||
static inline void
|
||||
isc_buffer_putuint16(isc_buffer_t *restrict b, const uint16_t val) {
|
||||
ISC_BUFFER_PUT_RESERVE(b, val);
|
||||
ISC_BUFFER_PUT_RESERVE(b, val, sizeof(val));
|
||||
|
||||
uint8_t *cp = isc_buffer_used(b);
|
||||
b->used += sizeof(val);
|
||||
@ -928,7 +927,7 @@ isc_buffer_getuint32(isc_buffer_t *restrict b) {
|
||||
|
||||
static inline void
|
||||
isc_buffer_putuint32(isc_buffer_t *restrict b, const uint32_t val) {
|
||||
ISC_BUFFER_PUT_RESERVE(b, val);
|
||||
ISC_BUFFER_PUT_RESERVE(b, val, sizeof(val));
|
||||
|
||||
uint8_t *cp = isc_buffer_used(b);
|
||||
b->used += sizeof(val);
|
||||
@ -957,7 +956,7 @@ isc_buffer_getuint48(isc_buffer_t *restrict b) {
|
||||
|
||||
static inline void
|
||||
isc_buffer_putuint48(isc_buffer_t *restrict b, const uint64_t val) {
|
||||
ISC_BUFFER_PUT_RESERVE(b, val);
|
||||
ISC_BUFFER_PUT_RESERVE(b, val, 6); /* 48-bits */
|
||||
|
||||
uint8_t *cp = isc_buffer_used(b);
|
||||
b->used += 6;
|
||||
|
Loading…
x
Reference in New Issue
Block a user