Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Anderson Lizardo <anderson.lizardo@openbossa.org>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [RFC v2 12/15] adaptername: Refactor handle_inotify_cb
Date: Fri, 31 Aug 2012 16:25:51 +0200	[thread overview]
Message-ID: <1623298.VeVY2Kx13o@uw000953> (raw)
In-Reply-To: <CAJdJm_NNYAHHVrr-uj97h7FEL0XatL5PuLnpOri6An4c-bz=mw@mail.gmail.com>

On Friday 31 of August 2012 16:19:28 Anderson Lizardo wrote:
> Hi Szymon,

Hi Anderson,

> 
> On Fri, Aug 31, 2012 at 8:40 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> > @@ -226,35 +226,41 @@ static int adaptername_probe(struct btd_adapter *adapter)
> >  static gboolean handle_inotify_cb(GIOChannel *channel, GIOCondition cond,
> >                                                                 gpointer data)
> >  {
> > -       char buf[EVENT_BUF_LEN];
> 
> Looks like EVENT_SIZE and EVENT_BUF_LEN defines are not used anymore
> so they can be removed.

Yeap, will remove it.

> 
> > +               err = g_io_channel_read_chars(channel, name, event.len, &len,
> > +                                                                       NULL);
> 
> No need to check for event.len <= FILENAME_MAX before the
> *read_chars() call ? (I don't know inotify, so I'm not sure about the
> allowed limits here)

Well, data is a file name which can't be > FILENAME_MAX+1. We would have to receive
some invalid data from kernel for that to happen... can we trust data from kernel?:)

So I'm also not sure if we really needs to validate that data...
This is what I've found in inotify-tools code about that situation:
  // oh... no.  this can't be happening.  An incomplete event.
  // Copy what we currently have into first element, call self to
  // read remainder.
  // oh, and they BETTER NOT overlap.
  // Boy I hope this code works.
  // But I think this can never happen due to how inotify is written.
They try to recover from that but if events overlap it is fubared anyway..

> 
> Or maybe using sizeof(name) instead of event.len ?

We can receive more events at once, so with that we could read name + part of next
inotify_event.

> 
> > +               if (err != G_IO_STATUS_NORMAL) {
> > +                       error("Error reading inotify event: %d", err);
> > +                       return FALSE;
> > +               }
> 
> Is it necessary to check whether event.len == len here ?

As above, this should not happen... but I'll move error reporting code into label
(to keep loop code short) and check for those anyway...

> 
> Otherwise a short read may not have the necessary "\0" for the
> strcmp() (but see below).
> 
> >
> > -               i += EVENT_SIZE + pevent->len;
> > -       }
> > +               if (strcmp(name, MACHINE_INFO_FILE) != 0)
> > +                       continue;
> 
> What about using strncmp() just to be safe?

Will fix that.

> 
> >
> > -       if (changed != FALSE) {
> >                 DBG(MACHINE_INFO_DIR MACHINE_INFO_FILE
> >                                 " changed, changing names for adapters");
> > +
> >                 manager_foreach_adapter((adapter_cb) adaptername_probe, NULL);
> > +               break;
> 
> what about having " if (strcmp(name, MACHINE_INFO_FILE) == 0) " and
> moving the code above to inside the if() ? The "unconditional" break
> at the end of the while() looks strange IMHO.

Wanted to keep indentation low, but yes, this might look strange.

> 
> >         }
> >
> >         return TRUE;
> 
> Regards,
> 

I'll send V3 in a moment.
Thanks for comments!

-- 
BR
Szymon Janc



  reply	other threads:[~2012-08-31 14:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 12:39 [RFC v2 00/15] Unaligned memory access fixes Szymon Janc
2012-08-31 12:39 ` [RFC v2 01/15] lib: Add host order unaligned access functions Szymon Janc
2012-08-31 12:39 ` [RFC v2 02/15] sap-u8500: Fix compile error due to unaligned memory access Szymon Janc
2012-08-31 12:39 ` [RFC v2 03/15] sdp: Use helper functions instead of bt_get_unaligned macro Szymon Janc
2012-08-31 12:40 ` [RFC v2 04/15] Add helper functions for putting integers on unaligned memory address Szymon Janc
2012-08-31 12:40 ` [RFC v2 05/15] sdp: Fix compilation errors due to unaligned memory access Szymon Janc
2012-08-31 12:40 ` [RFC v2 06/15] l2test: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 07/15] rctest: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 08/15] monitor: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 09/15] scotest: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 10/15] avrcp: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 11/15] sap: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 12/15] adaptername: Refactor handle_inotify_cb Szymon Janc
2012-08-31 13:19   ` Anderson Lizardo
2012-08-31 14:25     ` Szymon Janc [this message]
2012-08-31 14:29   ` [RFC v3] " Szymon Janc
2012-08-31 12:40 ` [RFC v2 13/15] sdpd-request: Fix build errors due to unaligned memory access Szymon Janc
2012-08-31 12:40 ` [RFC v2 14/15] sdpd-service: " Szymon Janc
2012-08-31 12:40 ` [RFC v2 15/15] hciemu: " Szymon Janc
2012-08-31 15:19   ` Anderson Lizardo
2012-09-03  6:42     ` Szymon Janc

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=1623298.VeVY2Kx13o@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=anderson.lizardo@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.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