]> git.ipfire.org Git - people/ms/suricata.git/commit - rust/src/rfb/rfb.rs
rfb: make sure size calculations do not overflow
authorSascha Steinbiss <satta@debian.org>
Sun, 29 Mar 2020 17:33:29 +0000 (19:33 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 30 Mar 2020 17:48:03 +0000 (19:48 +0200)
commit713c379427c43aa9be9be1dcf7c3ed79a91cab94
tree1d775a14724b644a58f85cdc3d3e767563fab671
parent2823bc5aed3ade2f916a9592c0ecf214bb62481b
rfb: make sure size calculations do not overflow

Addresses #3570 by extra checking of calculated size requests.

With the given input, the parser eventually arrived at
parser::parse_failure_reason() which parsed from the remaining four
bytes (describing the string length) that the failure string to follow
would be 4294967295 bytes long. While calculating the total size of the
data to request via AppLayerResult::incomplete(), adding the four bytes
for the parsed but not consumed string length caused the u32 length to
overflow, resulting in a much smaller value triggering the bug condition.

This problem was addressed by more careful checking of values in each step
that could overflow: one subtraction, one addition (which could overflow
the usize length values), and a final check to determine whether the result
still fit into the u32 values required by AppLayerResult::incomplete().
If so, we would safely convert the values and pass them to the result type.
If not, we simply return AppLayerResult::err() but do not erroneously and
silently request the wrong amount.
rust/src/rfb/rfb.rs