First time here? Check out the FAQ!
THIS IS A TEST INSTANCE. Feel free to ask and answer questions, but take care to avoid triggering too many notifications.
0

preference range

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.

kevin-gmail's avatar
1
kevin-gmail
asked 2018-10-17 14:54:13 +0000
grahamb's avatar
23.8k
grahamb
updated 2018-10-17 15:00:03 +0000
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

3 Answers

0

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.

Guy Harris's avatar
19.9k
Guy Harris
answered 2018-10-17 20:34:32 +0000
edit flag offensive 0 remove flag delete link

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's avatar Guy Harris (2018-10-19 23:00:45 +0000) edit
add a comment see more comments
0

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.

Guy Harris's avatar
19.9k
Guy Harris
answered 2018-10-19 23:02:44 +0000
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

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.

cmaynard's avatar
11.1k
cmaynard
answered 2018-10-17 15:38:14 +0000
edit flag offensive 0 remove flag delete link

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's avatar kevin-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's avatar cmaynard (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's avatar kevin-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's avatar cmaynard (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's avatar Guy Harris (2018-10-19 20:46:00 +0000) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer