Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Tor
Commits
7c26f88f
Commit
7c26f88f
authored
6 years ago
by
cypherpunks
Browse files
Options
Downloads
Patches
Plain Diff
rust/protover: validate unknown protocol names use only allowed characters
parent
82534282
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changes/bug27687
+4
-0
4 additions, 0 deletions
changes/bug27687
src/rust/protover/errors.rs
+3
-0
3 additions, 0 deletions
src/rust/protover/errors.rs
src/rust/protover/protover.rs
+33
-1
33 additions, 1 deletion
src/rust/protover/protover.rs
with
40 additions
and
1 deletion
changes/bug27687
0 → 100644
+
4
−
0
View file @
7c26f88f
o Minor bugfixes (rust):
- protover parsed and accepted unknown protocol names containing invalid
characters outside the range [A-Za-z0-9-]. Fixes bug 27687; bugfix on
0.3.3.1-alpha.
This diff is collapsed.
Click to expand it.
src/rust/protover/errors.rs
+
3
−
0
View file @
7c26f88f
...
...
@@ -18,6 +18,7 @@ pub enum ProtoverError {
ExceedsExpansionLimit
,
UnknownProtocol
,
ExceedsNameLimit
,
InvalidProtocol
,
}
/// Descriptive error messages for `ProtoverError` variants.
...
...
@@ -38,6 +39,8 @@ impl Display for ProtoverError {
=>
write!
(
f
,
"A protocol in the protover string we attempted to parse is unknown."
),
ProtoverError
::
ExceedsNameLimit
=>
write!
(
f
,
"An unrecognised protocol name was too long."
),
ProtoverError
::
InvalidProtocol
=>
write!
(
f
,
"A protocol name includes invalid characters."
),
}
}
}
This diff is collapsed.
Click to expand it.
src/rust/protover/protover.rs
+
33
−
1
View file @
7c26f88f
...
...
@@ -113,11 +113,17 @@ impl fmt::Display for UnknownProtocol {
}
}
fn
is_valid_proto
(
s
:
&
str
)
->
bool
{
s
.chars
()
.all
(|
c
|
c
.is_ascii_alphanumeric
()
||
c
==
'-'
)
}
impl
FromStr
for
UnknownProtocol
{
type
Err
=
ProtoverError
;
fn
from_str
(
s
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
if
s
.len
()
<=
MAX_PROTOCOL_NAME_LENGTH
{
if
!
is_valid_proto
(
s
)
{
Err
(
ProtoverError
::
InvalidProtocol
)
}
else
if
s
.len
()
<=
MAX_PROTOCOL_NAME_LENGTH
{
Ok
(
UnknownProtocol
(
s
.to_string
()))
}
else
{
Err
(
ProtoverError
::
ExceedsNameLimit
)
...
...
@@ -129,6 +135,9 @@ impl UnknownProtocol {
/// Create an `UnknownProtocol`, ignoring whether or not it
/// exceeds MAX_PROTOCOL_NAME_LENGTH.
fn
from_str_any_len
(
s
:
&
str
)
->
Result
<
Self
,
ProtoverError
>
{
if
!
is_valid_proto
(
s
)
{
return
Err
(
ProtoverError
::
InvalidProtocol
);
}
Ok
(
UnknownProtocol
(
s
.to_string
()))
}
}
...
...
@@ -777,6 +786,29 @@ mod test {
use
super
::
*
;
macro_rules!
parse_proto
{
(
$e:expr
)
=>
{{
let
proto
:
Result
<
UnknownProtocol
,
_
>
=
$e
.parse
();
let
proto2
=
UnknownProtocol
::
from_str_any_len
(
$e
);
assert_eq!
(
proto
,
proto2
);
proto
}};
}
#[test]
fn
test_protocol_from_str
()
{
assert!
(
parse_proto!
(
"Cons"
)
.is_ok
());
assert!
(
parse_proto!
(
"123"
)
.is_ok
());
assert!
(
parse_proto!
(
"1-2-3"
)
.is_ok
());
let
err
=
Err
(
ProtoverError
::
InvalidProtocol
);
assert_eq!
(
err
,
parse_proto!
(
"a_b_c"
));
assert_eq!
(
err
,
parse_proto!
(
"a b"
));
assert_eq!
(
err
,
parse_proto!
(
"a,"
));
assert_eq!
(
err
,
parse_proto!
(
"b."
));
assert_eq!
(
err
,
parse_proto!
(
"é"
));
}
macro_rules!
assert_protoentry_is_parseable
{
(
$e:expr
)
=>
(
let
protoentry
:
Result
<
ProtoEntry
,
ProtoverError
>
=
$e
.parse
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment