The definition of the PUBLISH message type indicates that the LSB are
independent, but uses a value of 0xF that clearly shows an attempt to
use a mask instead, but it results in all messages not having all flags
set to be rejected. A sane approach would have been to check for a mask
and an expected value. Let's just add a special case for it in function
mqtt_read_fixed_hdr() since that's for a single message type.
This can be backported anywhere.
[MQTT_CPT_CONNACK] = 0x00,
/* MQTT_CPT_PUBLISH flags can have different values (DUP, QoS, RETAIN), must be
- * check more carefully
+ * check more carefully (any combination of the 4 bits is valid).
*/
[MQTT_CPT_PUBLISH] = 0x0F,
uint8_t ptype = (type & 0xF0) >> 4;
uint8_t flags = type & 0x0F;
- if (ptype == MQTT_CPT_INVALID || ptype >= MQTT_CPT_ENTRIES || flags != mqtt_cpt_flags[ptype])
+ if (ptype == MQTT_CPT_INVALID || ptype >= MQTT_CPT_ENTRIES ||
+ (ptype != MQTT_CPT_PUBLISH && flags != mqtt_cpt_flags[ptype]))
return IST_NULL;
pkt->fixed_hdr.type = ptype;