diff options
author | Johan Hedberg <johan.hedberg@intel.com> | 2016-04-27 14:02:57 +0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2016-04-27 14:09:16 +0300 |
commit | 1b45686e605de58d35b1c29fefa4950ecf670fa6 (patch) | |
tree | e71463969a1769c10ec9c9158e181396332e2b0c /monitor/control.c | |
parent | 61bad31ced4deb82647b94cae58e0aaeeff27a7e (diff) | |
download | bluez-1b45686e605de58d35b1c29fefa4950ecf670fa6.tar.gz |
monitor: Fix processing left-over data
If there's enough data in the buffer after processing a packet we
should just continue looping and trying to parse it too.
Diffstat (limited to 'monitor/control.c')
-rw-r--r-- | monitor/control.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/monitor/control.c b/monitor/control.c index 710b97595..95df9802c 100644 --- a/monitor/control.c +++ b/monitor/control.c @@ -1062,23 +1062,25 @@ static void client_callback(int fd, uint32_t events, void *user_data) data->offset += len; - if (data->offset >= MGMT_HDR_SIZE) { + while (data->offset >= MGMT_HDR_SIZE) { struct mgmt_hdr *hdr = (struct mgmt_hdr *) data->buf; uint16_t pktlen = le16_to_cpu(hdr->len); + uint16_t opcode, index; - if (data->offset >= pktlen + MGMT_HDR_SIZE) { - uint16_t opcode = le16_to_cpu(hdr->opcode); - uint16_t index = le16_to_cpu(hdr->index); + if (data->offset < pktlen + MGMT_HDR_SIZE) + return; - packet_monitor(NULL, NULL, index, opcode, + opcode = le16_to_cpu(hdr->opcode); + index = le16_to_cpu(hdr->index); + + packet_monitor(NULL, NULL, index, opcode, data->buf + MGMT_HDR_SIZE, pktlen); - data->offset -= pktlen + MGMT_HDR_SIZE; + data->offset -= pktlen + MGMT_HDR_SIZE; - if (data->offset > 0) - memmove(data->buf, data->buf + - MGMT_HDR_SIZE + pktlen, data->offset); - } + if (data->offset > 0) + memmove(data->buf, data->buf + MGMT_HDR_SIZE + pktlen, + data->offset); } } |