]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix the assertion failure when putting 48-bit number to buffer
authorOndřej Surý <ondrej@isc.org>
Thu, 25 Jul 2024 18:30:03 +0000 (20:30 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 5 Aug 2024 07:55:18 +0000 (09:55 +0200)
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.

lib/isc/include/isc/buffer.h

index 8a2beac8f1f3a49a4b2a38b22893fbfb9e27e9d7..9c4a27d1d379aea208f589833989d274895946b0 100644 (file)
@@ -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;