2
0
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:
Ondřej Surý 2024-07-25 20:30:03 +02:00
parent 026024a6ae
commit 37dbd57c16
No known key found for this signature in database
GPG Key ID: 2820F37E873DEA41

View File

@ -857,22 +857,21 @@ isc_buffer_getuint8(isc_buffer_t *restrict b) {
return (val); return (val);
} }
#define ISC_BUFFER_PUT_RESERVE(b, v) \ #define ISC_BUFFER_PUT_RESERVE(b, v, s) \
{ \ { \
REQUIRE(ISC_BUFFER_VALID(b)); \ REQUIRE(ISC_BUFFER_VALID(b)); \
\ \
if (b->mctx) { \ if (b->mctx) { \
isc_result_t result = isc_buffer_reserve(b, \ isc_result_t result = isc_buffer_reserve(b, s); \
sizeof(val)); \
ENSURE(result == ISC_R_SUCCESS); \ ENSURE(result == ISC_R_SUCCESS); \
} \ } \
\ \
REQUIRE(isc_buffer_availablelength(b) >= sizeof(val)); \ REQUIRE(isc_buffer_availablelength(b) >= s); \
} }
static inline void static inline void
isc_buffer_putuint8(isc_buffer_t *restrict b, const uint8_t val) { 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); uint8_t *cp = isc_buffer_used(b);
b->used += sizeof(val); b->used += sizeof(val);
@ -900,7 +899,7 @@ isc_buffer_getuint16(isc_buffer_t *restrict b) {
static inline void static inline void
isc_buffer_putuint16(isc_buffer_t *restrict b, const uint16_t val) { 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); uint8_t *cp = isc_buffer_used(b);
b->used += sizeof(val); b->used += sizeof(val);
@ -928,7 +927,7 @@ isc_buffer_getuint32(isc_buffer_t *restrict b) {
static inline void static inline void
isc_buffer_putuint32(isc_buffer_t *restrict b, const uint32_t val) { 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); uint8_t *cp = isc_buffer_used(b);
b->used += sizeof(val); b->used += sizeof(val);
@ -957,7 +956,7 @@ isc_buffer_getuint48(isc_buffer_t *restrict b) {
static inline void static inline void
isc_buffer_putuint48(isc_buffer_t *restrict b, const uint64_t val) { 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); uint8_t *cp = isc_buffer_used(b);
b->used += 6; b->used += 6;