diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-15 10:27:27 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-15 19:07:38 -0500 |
commit | b58a2febe32f96204a94fb547e14a84c8fd32651 (patch) | |
tree | ec11e1ec82516f89083475491fec41cc2681cae0 | |
parent | f69510ba4b196ed40fce64f24b5b7799b68d182b (diff) | |
download | tor-b58a2febe32f96204a94fb547e14a84c8fd32651.tar.gz tor-b58a2febe32f96204a94fb547e14a84c8fd32651.zip |
Forbid u32::MAX as a protover range element in rust
Part of the 25249 fix to make rust match the C.
-rw-r--r-- | src/rust/protover/protover.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/rust/protover/protover.rs b/src/rust/protover/protover.rs index cc9be67b6f..64f350c6b7 100644 --- a/src/rust/protover/protover.rs +++ b/src/rust/protover/protover.rs @@ -9,6 +9,7 @@ use std::fmt; use std::collections::{HashMap, HashSet}; use std::ops::Range; use std::string::String; +use std::u32; use tor_util::strings::NUL_BYTE; @@ -204,9 +205,13 @@ impl Versions { versions.insert(p); } } else { - versions.insert(u32::from_str(piece).or( + let v = u32::from_str(piece).or( Err("invalid protocol entry"), - )?); + )?; + if v == u32::MAX { + return Err("invalid protocol entry"); + } + versions.insert(v); } if versions.len() > MAX_PROTOCOLS_TO_EXPAND { @@ -447,6 +452,10 @@ fn expand_version_range(range: &str) -> Result<Range<u32>, &'static str> { "cannot parse protocol range upper bound", ))?; + if lower == u32::MAX || higher == u32::MAX { + return Err("protocol range value out of range"); + } + // We can use inclusive range syntax when it becomes stable. let result = lower..higher + 1; |