From 78b8bda6f6ad12fbbed8238e4783c9561b1a2a04 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 8 Jan 2017 14:03:04 +0100 Subject: fix gen_log_config_set_mask() We were missing the last byte in the log config mask, resulting in unintended behavior. --- src/diag_log.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/diag_log.c b/src/diag_log.c index b670a8b..7a1eadf 100644 --- a/src/diag_log.c +++ b/src/diag_log.c @@ -50,6 +50,14 @@ struct diag_log_config_set_mask { uint8_t data[0]; } __attribute((packed)); +static inline unsigned int bytes_rqd_for_bit(unsigned int bit) +{ + if (bit % 8) + return bit/8 + 1; + else + return bit/8; +} + struct msgb *gen_log_config_set_mask(uint32_t equip_id, uint32_t last_item) { struct msgb *msg = msgb_alloc(DIAG_MAX_REQ_SIZE, "Diag Tx"); @@ -61,7 +69,7 @@ struct msgb *gen_log_config_set_mask(uint32_t equip_id, uint32_t last_item) dlcsm->hdr.operation = LOG_CONFIG_SET_MASK_OP; dlcsm->equip_id = equip_id; dlcsm->last_item = last_item; - msg->l3h = msgb_put(msg, dlcsm->last_item/8); + msg->l3h = msgb_put(msg, bytes_rqd_for_bit(dlcsm->last_item)); return msg; } @@ -74,8 +82,10 @@ int log_config_set_mask_bit(struct msgb *msg, uint32_t bit_in) unsigned int byte = bit_in / 8; unsigned int bit = bit_in % 8; - if (byte > dlcsm->last_item/8) + if (bit_in > dlcsm->last_item) { + fprintf(stderr, "bit %u is outside log config bitmask!\n", bit_in); return -1; + } mask[byte] |= (1 << bit); -- cgit v1.2.3