Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Fix overflow when detecting reserved transport params #1934

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8068,8 +8068,12 @@ impl<T> UnknownTransportParameter<T> {
///
/// See Section 18.1 in [RFC9000](https://datatracker.ietf.org/doc/html/rfc9000#name-reserved-transport-paramete).
pub fn is_reserved(&self) -> bool {
let n = (self.id - 27) / 31;
self.id == 31 * n + 27
if self.id < 27 {
false
} else {
let n = (self.id - 27) / 31;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simpler fix would be to have something like:

Suggested change
let n = (self.id - 27) / 31;
let n = self.id.saturating_sub(27) / 31;

to avoid the if / else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding explicit test cases for 0 and 27 TPs, just to make sure we cover the edge cases.

self.id == 31 * n + 27
}
}
}

Expand Down Expand Up @@ -9317,6 +9321,17 @@ mod tests {
assert!(reserved_unknown_param.is_reserved());
assert!(!not_reserved_unknown_param.is_reserved());
}

#[test]
fn transport_params_unknown_small_id_is_not_reserved() {
let param_with_small_id_not_reserved = UnknownTransportParameter::<&[u8]> {
id: 21,
value: &[0xau8; 280],
};

assert!(!param_with_small_id_not_reserved.is_reserved());
}

#[test]
fn unknown_version() {
let mut config = Config::new(0xbabababa).unwrap();
Expand Down