Skip to content

Commit e2e17d4

Browse files
committed
fix err shadowing in UPnP addAnyPortMapping
1 parent c31c288 commit e2e17d4

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

p2p/nat/natupnp.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,30 @@ func (n *upnp) addAnyPortMapping(protocol string, extport, intport int, ip net.I
107107
})
108108
}
109109
// For IGDv1 and v1 services we should first try to add with extport.
110+
var lastErr error
110111
for i := 0; i < retryCount+1; i++ {
111-
err := n.withRateLimit(func() error {
112+
lastErr = n.withRateLimit(func() error {
112113
return n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
113114
})
114-
if err == nil {
115+
if lastErr == nil {
115116
return uint16(extport), nil
116117
}
117-
log.Debug("Failed to add port mapping", "protocol", protocol, "extport", extport, "intport", intport, "err", err)
118+
log.Debug("Failed to add port mapping", "protocol", protocol, "extport", extport, "intport", intport, "err", lastErr)
118119
}
119120

120121
// If above fails, we retry with a random port.
121122
// We retry several times because of possible port conflicts.
122-
var err error
123123
for i := 0; i < randomCount; i++ {
124124
extport = n.randomPort()
125-
err := n.withRateLimit(func() error {
125+
lastErr = n.withRateLimit(func() error {
126126
return n.client.AddPortMapping("", uint16(extport), protocol, uint16(intport), ip.String(), true, desc, lifetimeS)
127127
})
128-
if err == nil {
128+
if lastErr == nil {
129129
return uint16(extport), nil
130130
}
131-
log.Debug("Failed to add random port mapping", "protocol", protocol, "extport", extport, "intport", intport, "err", err)
131+
log.Debug("Failed to add random port mapping", "protocol", protocol, "extport", extport, "intport", intport, "err", lastErr)
132132
}
133-
return 0, err
133+
return 0, lastErr
134134
}
135135

136136
func (n *upnp) randomPort() int {

p2p/rlpx/rlpx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"crypto/ecdsa"
2525
"crypto/hmac"
2626
"crypto/rand"
27+
"crypto/subtle"
2728
"encoding/binary"
2829
"errors"
2930
"fmt"
@@ -33,7 +34,6 @@ import (
3334
"net"
3435
"time"
3536

36-
"github.com/CortexFoundation/CortexTheseus/common/bitutil"
3737
"github.com/CortexFoundation/CortexTheseus/crypto"
3838
"github.com/CortexFoundation/CortexTheseus/crypto/ecies"
3939
"github.com/CortexFoundation/CortexTheseus/rlp"
@@ -677,6 +677,6 @@ func exportPubkey(pub *ecies.PublicKey) []byte {
677677

678678
func xor(one, other []byte) (xor []byte) {
679679
xor = make([]byte, len(one))
680-
bitutil.XORBytes(xor, one, other)
680+
subtle.XORBytes(xor, one, other)
681681
return xor
682682
}

0 commit comments

Comments
 (0)