Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendAndCheckResp crash when rsp has no elements #23

Open
Gealber opened this issue Sep 13, 2021 · 2 comments
Open

SendAndCheckResp crash when rsp has no elements #23

Gealber opened this issue Sep 13, 2021 · 2 comments

Comments

@Gealber
Copy link

Gealber commented Sep 13, 2021

I'm not too familiar with this library but I saw this question on SO, which highlight an issue in the function

func (c *Cmd) SendAndCheckResp(cp CmdParam, exp []byte) error {
	rsp, err := c.Send(cp)
	if err != nil {
		return err
	}
	// Don't care about the response
	if len(exp) == 0 {
		return nil
	}
	// Check the if status is one of the expected value
	if !bytes.Contains(exp, rsp[0:1]) {
		return fmt.Errorf("HCI command: '0x%04x' return 0x%02X, expect: [%X] ", cp.Opcode(), rsp[0], exp)
	}
	return nil
}

when the rsp is empty, or have capacity zero. The problem seems to be when trying to access the first two elements on rsp on line

if !bytes.Contains(exp, rsp[0:1]) {
....

I think this issue could be avoided just checking if len(rsp) == 0, and respond appropriately, but again I'm not familiar with the library so a better solution could be suggested by another person. I just thought is worth to report the issue.

@SachaPerson
Copy link

Having the same problem here !

@SachaPerson
Copy link

Anyone that can help with this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants