summaryrefslogtreecommitdiff
path: root/src/rust/protover/protoset.rs
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2018-03-27 22:46:14 +0000
committerIsis Lovecruft <isis@torproject.org>2018-04-02 19:59:16 +0000
commitc65088cb1943748412e1a390de655e20bdb28692 (patch)
treee2808db9bc2b138e89a11c23a52e8e618fe14e51 /src/rust/protover/protoset.rs
parent4b4e36a413bb5d0e2ea499dd6bc34b3d24bd3375 (diff)
downloadtor-c65088cb1943748412e1a390de655e20bdb28692.tar.gz
tor-c65088cb1943748412e1a390de655e20bdb28692.zip
rust: Fix ProtoSet and ProtoEntry to use the same DoS limits as C.
Previously, the limit for MAX_PROTOCOLS_TO_EXPAND was actually being applied in Rust to the maximum number of version (total, for all subprotocols). Whereas in C, it was being applied to the number of subprotocols that were allowed. This changes the Rust to match C's behaviour.
Diffstat (limited to 'src/rust/protover/protoset.rs')
-rw-r--r--src/rust/protover/protoset.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/rust/protover/protoset.rs b/src/rust/protover/protoset.rs
index f94e6299c9..4afc50edf8 100644
--- a/src/rust/protover/protoset.rs
+++ b/src/rust/protover/protoset.rs
@@ -8,7 +8,6 @@ use std::slice;
use std::str::FromStr;
use std::u32;
-use protover::MAX_PROTOCOLS_TO_EXPAND;
use errors::ProtoverError;
/// A single version number.
@@ -183,10 +182,6 @@ impl ProtoSet {
last_high = high;
}
- if self.len() > MAX_PROTOCOLS_TO_EXPAND {
- return Err(ProtoverError::ExceedsMax);
- }
-
Ok(self)
}
@@ -317,9 +312,15 @@ impl FromStr for ProtoSet {
/// assert!(protoset.contains(&5));
/// assert!(!protoset.contains(&10));
///
- /// // We can also equivalently call `ProtoSet::from_str` by doing:
+ /// // We can also equivalently call `ProtoSet::from_str` by doing (all
+ /// // implementations of `FromStr` can be called this way, this one isn't
+ /// // special):
/// let protoset: ProtoSet = "4-6,12".parse()?;
///
+ /// // Calling it (either way) can take really large ranges (up to `u32::MAX`):
+ /// let protoset: ProtoSet = "1-70000".parse()?;
+ /// let protoset: ProtoSet = "1-4294967296".parse()?;
+ ///
/// // There are lots of ways to get an `Err` from this function. Here are
/// // a few:
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("="));
@@ -327,7 +328,6 @@ impl FromStr for ProtoSet {
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("not_an_int"));
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("3-"));
/// assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-,4"));
- /// assert_eq!(Err(ProtoverError::ExceedsMax), ProtoSet::from_str("1-70000"));
///
/// // Things which would get parsed into an _empty_ `ProtoSet` are,
/// // however, legal, and result in an empty `ProtoSet`: