Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
10d5422c
Commit
10d5422c
authored
Jul 25, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mitm: Fix out of bounds error when checking software version in UA
parent
ae7e0982
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
caddyhttp/httpserver/mitm.go
caddyhttp/httpserver/mitm.go
+2
-0
caddyhttp/httpserver/mitm_test.go
caddyhttp/httpserver/mitm_test.go
+45
-0
No files found.
caddyhttp/httpserver/mitm.go
View file @
10d5422c
...
...
@@ -112,6 +112,8 @@ func getVersion(ua, softwareName string) float64 {
end
:=
strings
.
Index
(
ua
[
start
:
],
" "
)
if
end
<
0
{
end
=
len
(
ua
)
}
else
{
end
+=
start
}
strVer
:=
strings
.
Replace
(
ua
[
start
:
end
],
"-"
,
""
,
-
1
)
firstDot
:=
strings
.
Index
(
strVer
,
"."
)
...
...
caddyhttp/httpserver/mitm_test.go
View file @
10d5422c
...
...
@@ -352,3 +352,48 @@ func TestHeuristicFunctionsAndHandler(t *testing.T) {
}
}
}
func
TestGetVersion
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
[]
struct
{
UserAgent
string
SoftwareName
string
Version
float64
}{
{
UserAgent
:
"Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0"
,
SoftwareName
:
"Firefox"
,
Version
:
45.0
,
},
{
UserAgent
:
"Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0 more_stuff_here"
,
SoftwareName
:
"Firefox"
,
Version
:
45.0
,
},
{
UserAgent
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
,
SoftwareName
:
"Safari"
,
Version
:
537.36
,
},
{
UserAgent
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
,
SoftwareName
:
"Chrome"
,
Version
:
51.0270479
,
},
{
UserAgent
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
,
SoftwareName
:
"Mozilla"
,
Version
:
5.0
,
},
{
UserAgent
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
,
SoftwareName
:
"curl"
,
Version
:
-
1
,
},
}
{
actual
:=
getVersion
(
test
.
UserAgent
,
test
.
SoftwareName
)
if
actual
!=
test
.
Version
{
t
.
Errorf
(
"Test [%d]: Expected version=%f, got version=%f for %s in '%s'"
,
i
,
test
.
Version
,
actual
,
test
.
SoftwareName
,
test
.
UserAgent
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment