Skip to content

Use int.TryParse for the vehicle-reported RALLY_TOTAL and FENCE_TOTAL - #3777

Open
nicholasaleks wants to merge 1 commit into
ArduPilot:masterfrom
nicholasaleks:fix/mp-04-param-total-tryparse
Open

nicholasaleks wants to merge 1 commit into
ArduPilot:masterfrom
nicholasaleks:fix/mp-04-param-total-tryparse

Conversation

@nicholasaleks

Copy link
Copy Markdown

The post-connect block reads these two with int.Parse(param[...].ToString()). A vehicle chooses both the value and the reported type of any parameter it sends, and MAVLinkParam.ToString() returns the raw REAL32 for a REAL32, so the string can be "3.5", "NaN" or "1E+30". int.Parse throws FormatException on all three, and OverflowException on an integer above int.MaxValue.

The throw is not contained. The call sits in the if condition, &&-chained ahead of showui, so short-circuit evaluation runs it as soon as ContainsKey is true and before the try that opens on the following line. The surrounding post-connect block is the body of a BeginInvokeIfRequired lambda with no try/catch of its own, so the exception either unwinds into doConnect's catch and aborts the connection, or reaches Application.ThreadException and raises the generic error modal. Either way the operator cannot finish connecting, and the remaining post-connect setup does not run. No interaction is involved: parameters are downloaded automatically on connect.

int.TryParse removes the throw without depending on where the call sits relative to the try, and a count that is not an integer now reads as absent, which is the right reading of a malformed value.

Related to: https://github.com/nicholasaleks/infected-drones/tree/main/MP-04_param_total_connect_dos

The post-connect block reads these two with int.Parse(param[...].ToString()).
A vehicle chooses both the value and the reported type of any parameter it sends,
and MAVLinkParam.ToString() returns the raw REAL32 for a REAL32, so the string
can be "3.5", "NaN" or "1E+30". int.Parse throws FormatException on all three,
and OverflowException on an integer above int.MaxValue.

The throw is not contained. The call sits in the if condition, &&-chained ahead
of showui, so short-circuit evaluation runs it as soon as ContainsKey is true and
before the try that opens on the following line. The surrounding post-connect
block is the body of a BeginInvokeIfRequired lambda with no try/catch of its own,
so the exception either unwinds into doConnect's catch and aborts the connection,
or reaches Application.ThreadException and raises the generic error modal. Either
way the operator cannot finish connecting, and the remaining post-connect setup
does not run. No interaction is involved: parameters are downloaded automatically
on connect.

int.TryParse removes the throw without depending on where the call sits relative
to the try, and a count that is not an integer now reads as absent, which is the
right reading of a malformed value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant