owasp-amass/amass · error
invalid port range format
Error message
invalid port range format
What it means
convertPortRangeToSlice splits a range string on '-' and requires exactly two parts (start and end). This error is returned for strings that do not match the 'N-M' format, such as missing dashes or extra dashes.
Source
Thrown at config/scope.go:135
if err != nil {
return fmt.Errorf("invalid port string: %v", err)
}
s.Ports = append(s.Ports, portNum)
}
default:
return fmt.Errorf("unsupported port type: %T", p)
}
}
return nil
}
func convertPortRangeToSlice(portRange string) ([]int, error) {
var ports []int
parts := strings.Split(portRange, "-")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid port range format")
}
start, err := strconv.Atoi(parts[0])
if err != nil {
return nil, fmt.Errorf("invalid start port: %v", err)
}
end, err := strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("invalid end port: %v", err)
}
for i := start; i <= end; i++ {
ports = append(ports, i)
}
return ports, nil
}View on GitHub (pinned to 79299dce87)
Solutions
- Write the range as exactly start-end with one hyphen, e.g. '80-90'
- Remove extra hyphens or chained ranges; use separate entries for non-contiguous ports
- Ensure neither side of the hyphen is empty
Example fix
// before ports: ["80-90-100"] // after ports: ["80-90", "100"]
Defensive patterns
Strategy: validation
Validate before calling
matched, _ := regexp.MatchString(`^\d+-\d+$`, s); if !matched { return fmt.Errorf("port range must be N-M: %q", s) } Type guard
func isPortRange(s string) bool { m, _ := regexp.MatchString(`^\d+-\d+$`, s); return m } Prevention
- Exactly one hyphen per range
- No chained ranges like 80-85-90
- Regexp-validate range strings before config load
- Quote YAML values to avoid parse surprises
When it happens
Trigger: A port entry like '80-90-100', '80--90', '80-' or '-90' is passed to parsePorts and routed to convertPortRangeToSlice; strings.Split yields a part count other than 2.
Common situations: Chained ranges in config (80-85-90), trailing/leading hyphens from manual editing, negative-looking numbers, or typos like '8O-90' with two delimiters.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid port string: %v
- unsupported port type: %T
- invalid start port: %v
- invalid end port: %v
- no resolver keys were found in the resolvers section
AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06).
Data as JSON: /api/errors/a7800fb638ebdb04.
Report an issue: GitHub.