linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Michael Bradshaw <mjbshaw@gmail.com>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: Does sdp_seq_alloc_with_length() invoke undefined behavior?
Date: Mon, 20 May 2013 13:18:38 -0700	[thread overview]
Message-ID: <CABBYNZK2q_RHFSrhSn9npH_We877CGiztrVBx2HVMOrxC6Yfjg@mail.gmail.com> (raw)
In-Reply-To: <CAEhrai1s7Y0JHvd09k8y_xANE8EeLct-f_Z1FXWifRHF00kEew@mail.gmail.com>

Hi Michael,

On Mon, May 20, 2013 at 10:36 AM, Michael Bradshaw <mjbshaw@gmail.com> wrote:
> After reading some sample HID client code[1] that brought up the
> suspicious code in sdp_seq_alloc_with_length(), I'm wondering if it
> possibly invokes undefined behavior.
>
> I'll annotate the function:
> sdp_data_t *sdp_seq_alloc_with_length(void **dtds, void **values, int *length,
>                                       int len)
> {
>     sdp_data_t *curr = NULL, *seq = NULL;
>     int i;
>
>     for (i = 0; i < len; i++) {
>         // ... removed to be concise ...
>     }
>
>     return sdp_data_alloc_with_length(SDP_SEQ8, seq, length[i]);
> }
>
> That last line looks like it is accessing one-past-the-end of the
> length array when it says length[i]. Should the code execute that
> line, i == len, and if len represents the number of elements in the
> length array (which I think it does, but correct me if it does not),
> then it does indeed invoke undefined behavior.

This might actually be bug, the function is not that much that is
probably why we haven't notice this problem before. Anyway it is
leaking whenever it fails because we don't free the data allocated
previously.

> I'm hoping I could get some input from bluez developers who can say
> with confidence whether or not this is a bug (so I know whether or not
> I should open a bug report).

If you have the backtrace it is usually easier for us to tell but just
by looking at the code it seems very problematic.

--
Luiz Augusto von Dentz

      reply	other threads:[~2013-05-20 20:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 17:36 Does sdp_seq_alloc_with_length() invoke undefined behavior? Michael Bradshaw
2013-05-20 20:18 ` Luiz Augusto von Dentz [this message]

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=CABBYNZK2q_RHFSrhSn9npH_We877CGiztrVBx2HVMOrxC6Yfjg@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mjbshaw@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).