Ask Your Question
0

preference range

asked 2018-10-17 14:54:13 +0000

kevin-gmail gravatar image

updated 2018-10-17 15:00:03 +0000

grahamb gravatar image

In my decoder, I have registered a uint preference using: prefs_register_uint_preference(...)

On the GUI it works fine, but it allows "-1" to be input, which Wireshark converts to 4294967295.

I could apply a limit in my decoder, but that would be hidden from the user.

How can I either:

  1. Force the GUI to only take unsigned numbers (which it should do, being an uint type) or
  2. Register the preference with a range (i.e. 0 to 100 inclusive) for the GUI to implement.

Thanks for any help.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2018-10-17 15:38:14 +0000

cmaynard gravatar image

You could try registering the preference as a ranged value using prefs_register_range_preference(), where you can specify a max_value, but this will allow multiple values, which may or may not be desirable in your particular case.

edit flag offensive delete link more

Comments

I did look at that function, but it didn't look right with the range_t parameter. I could not see how multiple values could define a range coupled with the max_value!

kevin-gmail gravatar imagekevin-gmail ( 2018-10-17 15:57:20 +0000 )edit

Have a look at some of the dissectors that make use of it, such as the HTTP dissector. For example, the default SCTP port "range" is 80, but if you try to change it to something like "80,70000" or "80-70000", the background turns red, which gives the user some indication of an invalid maximum value since the limit is 65535. Unfortunately, if you ignore this and click OK anyway, this just truncates the maximum port to 7000 instead of not allowing it to be saved at all, which is probably what should occur.

And now that I've taken a second look at this, it seems that "80,-1" is also allowed and worse, there's no indication given to indicate that it's invalid. If you click OK now, the next time you look at the preference, it is changed to "80,1". Maybe a value of 1 ...(more)

cmaynard gravatar imagecmaynard ( 2018-10-17 16:13:06 +0000 )edit

My variable is in my decoder, Wireshark will not use this variable. I only want to user to set a single number in the GUI, not a range. I would like the GUI to enforce an upper limit (i.e. 0-100). I don't see prefs_register_range_preference() as what I need.

kevin-gmail gravatar imagekevin-gmail ( 2018-10-18 14:00:41 +0000 )edit

OK, but making use of a range preference doesn't mean that you can only specify a range; you can specify a single number. I'm not saying this is ideal, but it might be better than what you have now, because you can at least enforce an upper limit.

cmaynard gravatar imagecmaynard ( 2018-10-18 14:41:58 +0000 )edit

it seems that "80,-1" is also allowed and worse, there's no indication given to indicate that it's invalid.

It is valid - it's a list of subranges, the first of which contains only 80 (80-80), and the second of which starts with the beginning value and runs up to 1 ({min}-1). (Yes, that's surprising, but it's valid - that's how the range syntax works. It uses - as an indication of a subrange, and allows subranges without a start or end.)

If you click OK now, the next time you look at the preference, it is changed to "80,1"

80-80 is the same as 80 and, if {min} is 1, that makes {min}-1 be 1-1, which is the same as 1.

Guy Harris gravatar imageGuy Harris ( 2018-10-19 20:46:00 +0000 )edit
0

answered 2018-10-19 23:02:44 +0000

Guy Harris gravatar image

We should probably add an API for registering "constrained" unsigned integer preferences (to borrow a term from ASN.1, as I remember) - it would specify a minimum and maximum value.

That way, we can do the bounds checking in the preferences code, and, if we use a spin box for them, set minimum and maximum values.

Again, this should be tracked with a bug on the Wireshark Bugzilla.

edit flag offensive delete link more
0

answered 2018-10-17 20:34:32 +0000

Guy Harris gravatar image

On the GUI it works fine, but it allows "-1" to be input

That's a bug; if it's unsigned, you shouldn't be allowed to specify a sign. (Yes, that means that strtoul() and company don't do enough error checking for code that wants to disallow signs for unaligned values.)

Please file a bug on that in the Wireshark Bugzilla.

edit flag offensive delete link more

Comments

OK, so I've added changed some uses of strtoul() to use ws_basestrtou32() in the preferences and range code, which means that, at least from the CLI, negative numbers are rejected for unsigned-integer preferences.

For the GUI, there are a number of things we can do, including either using validators for integral preferences, as I suggested for range preferences, or using spin boxes for integral preferences.

Guy Harris gravatar imageGuy Harris ( 2018-10-19 23:00:45 +0000 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-10-17 14:54:13 +0000

Seen: 559 times

Last updated: Oct 19 '18