]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
rust/protover: fix hyphen parsing bug in ProtoSet::from_str()
authorcypherpunks <cypherpunks@torproject.org>
Tue, 7 Aug 2018 00:45:33 +0000 (00:45 +0000)
committercypherpunks <cypherpunks@torproject.org>
Fri, 17 Aug 2018 13:27:24 +0000 (13:27 +0000)
It was parsing "1-2-3" as if it were 1-2, ignoring the 2nd hyphen
and everything after.

Introduced in d1820c1516a31a149fc51a9e5126bf899e4c4e08.

Fixes #27164; bugfix on 0.3.3.1-alpha.

changes/bug27164 [new file with mode: 0644]
src/rust/protover/protoset.rs

diff --git a/changes/bug27164 b/changes/bug27164
new file mode 100644 (file)
index 0000000..d04d2f2
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (rust):
+    - Protover parsing was ignoring a 2nd hyphen and everything after it,
+      accepting entries like "Link=1-5-foo". Fixes bug 27164; bugfix on
+      0.3.3.1-alpha.
index 4afc50edf8745a4954cfb70c6d3271cc776f694a..61b21ede98f71d919bb7c0a39755c4ce8d71cbbc 100644 (file)
@@ -348,7 +348,7 @@ impl FromStr for ProtoSet {
             if p.is_empty() {
                 continue;
             } else if p.contains('-') {
-                let mut pair = p.split('-');
+                let mut pair = p.splitn(2, '-');
 
                 let low  = pair.next().ok_or(ProtoverError::Unparseable)?;
                 let high = pair.next().ok_or(ProtoverError::Unparseable)?;
@@ -538,6 +538,18 @@ mod test {
         assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1"));
     }
 
+    #[test]
+    fn test_versions_from_str_hyphens() {
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("--1"));
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("-1-2"));
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1--2"));
+    }
+
+    #[test]
+    fn test_versions_from_str_triple() {
+        assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1-2-3"));
+    }
+
     #[test]
     fn test_versions_from_str_1exclam() {
         assert_eq!(Err(ProtoverError::Unparseable), ProtoSet::from_str("1,!"));