[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] rust/protover: don't accept whitespace in ProtoSet::from_str()



commit 7b7dd9ae1c429248fdb7d6062f1af4c360527f00
Author: cypherpunks <cypherpunks@xxxxxxxxxxxxxx>
Date:   Fri Aug 17 03:22:47 2018 +0000

    rust/protover: don't accept whitespace in ProtoSet::from_str()
    
    It's impossible for spaces to get here, since spaces are used as
    separators between individual protocol entries higher up.
    
    And it shouldn't ignore whitespace that isn't a literal space
    character, because that would differ from the C implementation.
    
    These were added in 9925d2e68709aa7346f4c5bc98ea1349df6741f3.
    
    Fixes #27177. Bugfix on 0.3.3.5-rc.
---
 changes/bug27177              |  4 ++++
 src/rust/protover/protoset.rs | 15 ++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/changes/bug27177 b/changes/bug27177
new file mode 100644
index 000000000..b03bbc96e
--- /dev/null
+++ b/changes/bug27177
@@ -0,0 +1,4 @@
+  o Minor bugfixes (rust):
+    - Protover parsing was accepting the presence of whitespace in version
+      strings, which the C implementation would choke on, e.g. "Desc=1\t,2".
+      Fixes bug 27177; bugfix on 0.3.3.5-rc.
diff --git a/src/rust/protover/protoset.rs b/src/rust/protover/protoset.rs
index 4afc50edf..bb6794b6a 100644
--- a/src/rust/protover/protoset.rs
+++ b/src/rust/protover/protoset.rs
@@ -340,11 +340,9 @@ impl FromStr for ProtoSet {
     /// ```
     fn from_str(version_string: &str) -> Result<Self, Self::Err> {
         let mut pairs: Vec<(Version, Version)> = Vec::new();
-        let pieces: ::std::str::Split<char> = version_string.trim().split(',');
-
-        for piece in pieces {
-            let p: &str = piece.trim();
+        let pieces: ::std::str::Split<char> = version_string.split(',');
 
+        for p in pieces {
             if p.is_empty() {
                 continue;
             } else if p.contains('-') {
@@ -369,7 +367,7 @@ impl FromStr for ProtoSet {
                 pairs.push((v, v));
             }
         }
-        // If we were passed in an empty string, or a bunch of whitespace, or
+        // If we were passed in an empty string, or
         // simply a comma, or a pile of commas, then return an empty ProtoSet.
         if pairs.len() == 0 {
             return Ok(ProtoSet::default());
@@ -549,6 +547,13 @@ mod test {
     }
 
     #[test]
+    fn test_versions_from_str_whitespace() {
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,2\n"));
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1\r,2"));
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,\t2"));
+    }
+
+    #[test]
     fn test_versions_from_str_overlap() {
         assert_eq!(Err(ProtoverError::Overlap), ProtoSet::from_str("1-3,2-4"));
     }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits