Merge pull request #12 from roseteromeo56/alert-autofix-9

Potential fix for code scanning alert no. 9: Incorrect conversion between integer types
This commit is contained in:
Romeo Rosete 2025-05-20 10:18:10 -04:00 committed by GitHub
commit 73a8af0c4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -336,7 +336,7 @@ func parseExtAddr(spec string) (ip net.IP, port int, ok bool) {
return nil, 0, false
}
port, err = strconv.Atoi(portstr)
if err != nil {
if err != nil || port < 0 || port > 65535 {
return nil, 0, false
}
return ip, port, true

View file

@ -205,6 +205,10 @@ func (ln *LocalNode) SetFallbackIP(ip net.IP) {
// SetFallbackUDP sets the last-resort UDP-on-IPv4 port. This port is used
// if no endpoint prediction can be made.
func (ln *LocalNode) SetFallbackUDP(port int) {
if port < 0 || port > 65535 {
log.Error("Invalid port value, must be in range 0-65535", "port", port)
return
}
ln.mu.Lock()
defer ln.mu.Unlock()