Skip to content

Commit b837181

Browse files
committed
fix: HCI should not read data past the end of the available buffer to store it. To fix #396
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent dc98e52 commit b837181

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

hci.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ func (h *hci) poll() error {
197197
// perform read only if more data is available
198198
available := h.transport.Buffered()
199199
if available > 0 {
200+
// limit to buffer size
201+
if available > len(h.buf)-h.end {
202+
available = len(h.buf) - h.end
203+
}
204+
205+
// read in 4 byte aligned chunks
200206
aligned := available + (4-(available%4))%4
201207
n, err := h.transport.Read(h.buf[h.end : h.end+aligned])
202208
if err != nil {

0 commit comments

Comments
 (0)