owasp-amass/amass · error
invalid port string: %v
Error message
invalid port string: %v
What it means
parsePorts accepts port entries as strings or ints; a string entry must be a plain integer or a range like '80-90'. When a string is neither and strconv.Atoi fails, this error wraps the Atoi error. Ranges are handled earlier, so this fires only for non-range strings.
Source
Thrown at config/scope.go:118
}
for _, port := range s.PortsRaw {
switch p := port.(type) {
case int: // If it's an integer, just append
s.Ports = append(s.Ports, p)
case string: // If it's a string, check if it's a range or a single port
if strings.Contains(p, "-") {
// Handle port range
portRange, err := convertPortRangeToSlice(p)
if err != nil {
return err
}
s.Ports = append(s.Ports, portRange...)
} else {
// Handle single port string
portNum, err := strconv.Atoi(p)
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")
}View on GitHub (pinned to 79299dce87)
Solutions
- Change the entry to a numeric string, e.g. '80' instead of 'http'
- Split comma-separated values '80,443' into separate entries 80 and 443
- Trim whitespace/hidden characters from the string entry
- Use the range syntax '80-90' if a span of ports was intended
Example fix
// before (config) ports: ["http", "80,443"] // after ports: [80, 443]
Defensive patterns
Strategy: validation
Validate before calling
for _, p := range ports { if s, ok := p.(string); ok && !strings.Contains(s, "-") { if _, err := strconv.Atoi(strings.TrimSpace(s)); err != nil { return err } } } Type guard
func isNumericPortString(s string) bool { _, err := strconv.Atoi(strings.TrimSpace(s)); return err == nil } Try / catch
if err := parsePorts(raw); err != nil { return fmt.Errorf("ports config invalid: %w", err) } Prevention
- Use integers for ports in config files
- No service names or comma-packed strings
- Trim whitespace on values
- Use range syntax '80-90' for spans
When it happens
Trigger: A scope Ports entry is a string like 'http', '80,443', '80 ', or '0x50' — anything strconv.Atoi cannot parse after the range path (contains '-') was not taken.
Common situations: Config lists service names or comma-separated ports in a single string instead of separate numeric entries; whitespace or typos like '8o'; ports pasted from nmap output.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- invalid start port: %v
- invalid end port: %v
- unsupported port type: %T
- invalid port range format
- 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/f08165d7b8b808df.
Report an issue: GitHub.