Linux bluetooth development
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>,
	linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH BlueZ] Add support for parsing the remote name during LE Scan
Date: Fri, 14 Oct 2011 14:34:07 +0300	[thread overview]
Message-ID: <20111014113407.GA15909@fusion.localdomain> (raw)
In-Reply-To: <20111014080144.GA2125@fusion.localdomain>

Hi Vinicius,

On Fri, Oct 14, 2011, Johan Hedberg wrote:
> Hi Vinicius,
> 
> On Thu, Oct 13, 2011, Vinicius Costa Gomes wrote:
> > +	while (len < HCI_MAX_EIR_LENGTH - 1) {
> > +		uint8_t field_len = eir_data[0];
> > +
> > +		/* Check for the end of EIR */
> > +		if (field_len == 0)
> > +			break;
> 
> I suppose there should also be a check for:
> 
> 	if (len + field_len > HCI_MAX_EIR_LENGTH)
> 		goto failed;
> 
> Otherwise you're gonna access past the end of the eir_data buffer when
> you do the memcpy later.
> 
> > +
> > +		switch (eir_data[1]) {
> > +		case EIR_NAME_SHORT:
> > +		case EIR_NAME_COMPLETE:
> > +			if (field_len > HCI_MAX_NAME_LENGTH)
> > +				goto failed;
> 
> If you add the if-statement I suggested earlier you can remove this one
> (since it becomes redundant).
> 
> > +
> > +			memcpy(name, &eir_data[2], field_len - 1);
> > +			return;
> > +		}
> > +
> > +		len += field_len + 1;
> > +		eir_data += field_len + 1;
> > +	}
> > +
> > +failed:
> > +	sprintf(name, "(unknown)");
> > +	return;
> > +}
> 
> Please remove the unnecessary return statement here.

I had a slight confusion with my local patch handling and your patch
went upstream by mistake. So, I ended up fixing these issues by myself.
There were actually several more issues which I spotted and fixed in the
same go:

- read_flags() had missing checks too
- The LE EIR data length is variable and max 0x1f (31) bytes, i.e. not
  HCI_MAX_EIR_LENGTH
- Because of the above limit the name is max 29 bytes

Please check upstream (github) and verify that I didn't make any mistake
(since I was only able to do only limited testing here).

Johan

  reply	other threads:[~2011-10-14 11:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06 14:42 [PATCH BlueZ 1/2] Add support for cancelling a LE Scan with Control-C Vinicius Costa Gomes
2011-10-06 14:42 ` [PATCH BlueZ 2/2] Add support for parsing the remote name during LE Scan Vinicius Costa Gomes
2011-10-11 11:47   ` Johan Hedberg
2011-10-13 16:41   ` [PATCH BlueZ] " Vinicius Costa Gomes
2011-10-13 21:39     ` Vinicius Costa Gomes
2011-10-14  8:01       ` Johan Hedberg
2011-10-14 11:34         ` Johan Hedberg [this message]
2011-10-06 15:49 ` [PATCH BlueZ 1/2] Add support for cancelling a LE Scan with Control-C Johan Hedberg
2011-10-06 16:22   ` Vinicius Costa Gomes
2011-10-06 18:03 ` [PATCH BlueZ] " Vinicius Costa Gomes
2011-10-07 20:27   ` Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111014113407.GA15909@fusion.localdomain \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=vinicius.gomes@openbossa.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox