Browse Source

rpc: fix RPC client doesn't handle url's without ports (#6507)

pull/6575/head
JayT106 3 years ago
committed by GitHub
parent
commit
cb63ab4ac0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 2 deletions
  1. +2
    -1
      CHANGELOG_PENDING.md
  2. +9
    -1
      rpc/jsonrpc/client/http_json_client.go
  3. +28
    -0
      rpc/jsonrpc/client/http_json_client_test.go

+ 2
- 1
CHANGELOG_PENDING.md View File

@ -126,5 +126,6 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash)
- [blockchain/v1] [\#5701](https://github.com/tendermint/tendermint/pull/5701) Handle peers without blocks (@melekes)
- [blockchain/v1] \#5711 Fix deadlock (@melekes)
- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (@cmwaters)
- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (cmwaters)
- [rpc] \#6507 fix RPC client doesn't handle url's without ports (@JayT106)
- [statesync] \#6463 Adds Reverse Sync feature to fetch historical light blocks after state sync in order to verify any evidence (@cmwaters)

+ 9
- 1
rpc/jsonrpc/client/http_json_client.go View File

@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strings"
"time"
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
@ -370,6 +371,7 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error),
}
protocol := u.Scheme
padding := u.Scheme
// accept http(s) as an alias for tcp
switch protocol {
@ -378,7 +380,13 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error),
}
dialFn := func(proto, addr string) (net.Conn, error) {
return net.Dial(protocol, u.GetDialAddress())
var timeout = 10 * time.Second
if !u.isUnixSocket && strings.LastIndex(u.Host, ":") == -1 {
u.Host = fmt.Sprintf("%s:%s", u.Host, padding)
return net.DialTimeout(protocol, u.GetDialAddress(), timeout)
}
return net.DialTimeout(protocol, u.GetDialAddress(), timeout)
}
return dialFn, nil


+ 28
- 0
rpc/jsonrpc/client/http_json_client_test.go View File

@ -84,3 +84,31 @@ func Test_parsedURL(t *testing.T) {
})
}
}
func TestMakeHTTPDialerURL(t *testing.T) {
remotes := []string{"https://foo-bar.com", "http://foo-bar.com"}
for _, remote := range remotes {
u, err := newParsedURL(remote)
require.NoError(t, err)
dialFn, err := makeHTTPDialer(remote)
require.Nil(t, err)
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
require.NoError(t, err)
require.NotNil(t, addr)
}
errorURLs := []string{"tcp://foo-bar.com", "ftp://foo-bar.com"}
for _, errorURL := range errorURLs {
u, err := newParsedURL(errorURL)
require.NoError(t, err)
dialFn, err := makeHTTPDialer(errorURL)
require.Nil(t, err)
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
require.Error(t, err)
require.Nil(t, addr)
}
}

Loading…
Cancel
Save