Skip to content

Commit caf74c0

Browse files
dgarskedanielinux
authored andcommitted
Peer review fixes (thank you danielinux)
1 parent c43bdab commit caf74c0

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/port/stm32h563/mqtt_broker_persist_flash.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,38 @@
9696
#define KVF_TOMB_MARK 0x00U
9797

9898
#define KVF_MAX_KEY 256U /* per hooks API contract */
99-
#define KVF_MAX_BLOB 1280U /* >= largest GCM-wrapped record */
99+
100+
/* Largest GCM-wrapped blob the wolfMQTT persist codec can emit, derived
101+
* from the broker config macros so a config bump cannot silently exceed
102+
* it. Encrypted blob layout (wolfMQTT src/mqtt_broker_persist.c):
103+
* WMQB header (12) + GCM nonce (12) + body + GCM tag (16). */
104+
#define KVF_WRAP_OVERHEAD (12U + 12U + 16U)
105+
/* Largest record bodies the codec can emit:
106+
* SUBS: 2 + count*(1+1+2+filter), count <= BROKER_MAX_SUBS,
107+
* filter strlen <= BROKER_MAX_FILTER_LEN-1
108+
* OUTQ: 26 + topic + payload (covers RETAINED, which is 6 smaller;
109+
* OUTQ itself is a no-op under WOLFMQTT_STATIC_MEMORY but
110+
* keeping it in the bound makes it config-proof) */
111+
#define KVF_SUBS_BODY_MAX (2U + (BROKER_MAX_SUBS) * \
112+
(4U + (BROKER_MAX_FILTER_LEN - 1U)))
113+
#define KVF_OUTQ_BODY_MAX (26U + (BROKER_MAX_TOPIC_LEN - 1U) + \
114+
(BROKER_MAX_PAYLOAD_LEN))
115+
#define KVF_BODY_MAX ((KVF_SUBS_BODY_MAX > KVF_OUTQ_BODY_MAX) ? \
116+
KVF_SUBS_BODY_MAX : KVF_OUTQ_BODY_MAX)
117+
#define KVF_MAX_BLOB (KVF_BODY_MAX + KVF_WRAP_OVERHEAD)
118+
100119
#define KVF_PAYLOAD_PAD_MAX (((KVF_MAX_KEY + KVF_MAX_BLOB) + 15U) & ~15U)
101120

102121
#define KVF_ALIGN16(x) (((uint32_t)(x) + 15U) & ~15U)
103122
/* stride = header + commit + padded payload + tombstone */
104123
#define KVF_STRIDE(klen, blen) (3U * KVF_QW + KVF_ALIGN16((klen) + (blen)))
105124

125+
/* One max-size record (plus the bank header quad-word) must fit in a
126+
* bank, or kv_put could never store it even after compaction. */
127+
typedef char kvf_assert_rec_fits_bank[
128+
(KVF_STRIDE(KVF_MAX_KEY, KVF_MAX_BLOB) + KVF_QW <= KVF_BANK_SIZE) ?
129+
1 : -1];
130+
106131
/* ----- STM32H5 FLASH controller (TZEN=0 / non-secure view) ---------- */
107132
#define KVF_FLASH_BASE 0x40022000UL
108133
#define KVF_FLASH_KEYR (*(volatile uint32_t *)(KVF_FLASH_BASE + 0x04))

0 commit comments

Comments
 (0)