Linux IEEE 802.15.4 and 6LoWPAN development
 help / color / mirror / Atom feed
From: Alexander Aring <alex.aring@gmail.com>
To: Stefan Schmidt <stefan@osg.samsung.com>
Cc: linux-wpan@vger.kernel.org
Subject: Re: [PATCH wpan-tools] mac: range checking for command accepting only 0 or 1
Date: Wed, 19 Aug 2015 16:33:35 +0200	[thread overview]
Message-ID: <20150819143331.GB31917@omega> (raw)
In-Reply-To: <55D49291.6090702@osg.samsung.com>

On Wed, Aug 19, 2015 at 04:28:33PM +0200, Stefan Schmidt wrote:
> Hello.
> 
> On 19/08/15 16:22, Alexander Aring wrote:
> >Hi Stefan,
> >
> >On Wed, Aug 19, 2015 at 04:13:24PM +0200, Stefan Schmidt wrote:
> >>lbt and ackreq_default only accept 0or 1 as arguments which we did not
> >>acount for so far. Testing invalid arguments and checking teh return
> >>code uncovered this one.
> >>
> >>Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
> >>---
> >>  src/mac.c | 4 ++++
> >>  1 file changed, 4 insertions(+)
> >>
> >>diff --git a/src/mac.c b/src/mac.c
> >>index 76db58f..26c6fc5 100644
> >>--- a/src/mac.c
> >>+++ b/src/mac.c
> >>@@ -175,6 +175,8 @@ static int handle_lbt_mode(struct nl802154_state *state,
> >>  	mode = strtoul(argv[0], &end, 0);
> >>  	if (*end != '\0')
> >>  		return 1;
> >>+	if (mode != 0 && mode != 1)
> >>+		return 1;
> >>  	NLA_PUT_U8(msg, NL802154_ATTR_LBT_MODE, mode);
> >>@@ -202,6 +204,8 @@ static int handle_ackreq_default(struct nl802154_state *state,
> >>  	ackreq = strtoul(argv[0], &end, 0);
> >>  	if (*end != '\0')
> >>  		return 1;
> >>+	if (ackreq != 0 && ackreq != 1)
> >>+		return 1;
> >range checks should be handled by kernelspace. Currently we do a "!!var"
> >conversion there.
> 
> Which is why any value > 0 gets set to 1 here.
> 
> >Maybe we should change it there and accept "1" or "0".
> 
> I think that would indeed be better.
> 
> >We should never handle "if a range is valid or not" inside userspace,
> >otherwise other applications which talking to nl802154 can do a
> >different handling then.
> 
> I disagree here. We should for sure do range checking in the kernel but we
> should as well check for it in iwpan and get the return code right.
> 

this should be handled by returning -EINVAL in the handler of nl802154. Try a:

iwpan dev wpan0 set max_frame_retries 8

which should always return "-EINVAL" inside nl802154.

The return is:

command failed: Invalid argument (-22)



Is this okay? Or do you expect a different handling?

- Alex

  reply	other threads:[~2015-08-19 14:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-19 14:13 [PATCH wpan-tools] mac: range checking for command accepting only 0 or 1 Stefan Schmidt
2015-08-19 14:22 ` Alexander Aring
2015-08-19 14:28   ` Stefan Schmidt
2015-08-19 14:33     ` Alexander Aring [this message]
2015-08-19 14:38       ` Alexander Aring
2015-08-19 15:27       ` Stefan Schmidt
2015-08-19 15:58         ` Alexander Aring

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=20150819143331.GB31917@omega \
    --to=alex.aring@gmail.com \
    --cc=linux-wpan@vger.kernel.org \
    --cc=stefan@osg.samsung.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