Potential fix for code scanning alert no. 9: Incorrect conversion between integer types

Romeo Rosete

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Romeo Rosete 2025-05-20 10:14:03 -04:00 committed by GitHub
parent 4c939b5196
commit 6e96ff3204
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 return nil, 0, false
} }
port, err = strconv.Atoi(portstr) port, err = strconv.Atoi(portstr)
if err != nil { if err != nil || port < 0 || port > 65535 {
return nil, 0, false return nil, 0, false
} }
return ip, port, true 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 // SetFallbackUDP sets the last-resort UDP-on-IPv4 port. This port is used
// if no endpoint prediction can be made. // if no endpoint prediction can be made.
func (ln *LocalNode) SetFallbackUDP(port int) { 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() ln.mu.Lock()
defer ln.mu.Unlock() defer ln.mu.Unlock()