Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-tcp-transport
Commits
3ddabafa
Commit
3ddabafa
authored
Apr 02, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: don't allow dialing DNS addresses
See
https://github.com/libp2p/go-libp2p/issues/841
parent
e74d5f34
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
tcp.go
tcp.go
+3
-1
tcp_test.go
tcp_test.go
+21
-0
No files found.
tcp.go
View file @
3ddabafa
...
@@ -70,10 +70,12 @@ func NewTCPTransport(upgrader *tptu.Upgrader) *TcpTransport {
...
@@ -70,10 +70,12 @@ func NewTCPTransport(upgrader *tptu.Upgrader) *TcpTransport {
return
&
TcpTransport
{
Upgrader
:
upgrader
,
ConnectTimeout
:
DefaultConnectTimeout
}
return
&
TcpTransport
{
Upgrader
:
upgrader
,
ConnectTimeout
:
DefaultConnectTimeout
}
}
}
var
dialMatcher
=
mafmt
.
And
(
mafmt
.
IP
,
mafmt
.
Base
(
ma
.
P_TCP
))
// CanDial returns true if this transport believes it can dial the given
// CanDial returns true if this transport believes it can dial the given
// multiaddr.
// multiaddr.
func
(
t
*
TcpTransport
)
CanDial
(
addr
ma
.
Multiaddr
)
bool
{
func
(
t
*
TcpTransport
)
CanDial
(
addr
ma
.
Multiaddr
)
bool
{
return
mafmt
.
TCP
.
Matches
(
addr
)
return
dialMatcher
.
Matches
(
addr
)
}
}
func
(
t
*
TcpTransport
)
maDial
(
ctx
context
.
Context
,
raddr
ma
.
Multiaddr
)
(
manet
.
Conn
,
error
)
{
func
(
t
*
TcpTransport
)
maDial
(
ctx
context
.
Context
,
raddr
ma
.
Multiaddr
)
(
manet
.
Conn
,
error
)
{
...
...
tcp_test.go
View file @
3ddabafa
...
@@ -36,6 +36,27 @@ func TestTcpTransport(t *testing.T) {
...
@@ -36,6 +36,27 @@ func TestTcpTransport(t *testing.T) {
envReuseportVal
=
true
envReuseportVal
=
true
}
}
func
TestTcpTransportCantDialDNS
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
2
;
i
++
{
dnsa
,
err
:=
ma
.
NewMultiaddr
(
"/dns4/example.com/tcp/1234"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
tpt
:=
NewTCPTransport
(
&
tptu
.
Upgrader
{
Secure
:
makeInsecureTransport
(
t
),
Muxer
:
new
(
mplex
.
Transport
),
})
if
tpt
.
CanDial
(
dnsa
)
{
t
.
Fatal
(
"shouldn't be able to dial dns"
)
}
envReuseportVal
=
false
}
envReuseportVal
=
true
}
func
TestTcpTransportCantListenUtp
(
t
*
testing
.
T
)
{
func
TestTcpTransportCantListenUtp
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
2
;
i
++
{
for
i
:=
0
;
i
<
2
;
i
++
{
utpa
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/udp/0/utp"
)
utpa
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/udp/0/utp"
)
...
...
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