Billionmail/BillionMail · error
invalid port:
Error message
invalid port:
What it means
AllowPort in core/internal/service/public/common.go opens a port in the firewall. Before touching the firewall it validates the port number with IsPort; if the integer is outside the valid port range (or otherwise invalid), it returns "invalid port: <port>". ReloadFirewall only runs when the call succeeds.
Source
Thrown at core/internal/service/public/common.go:2274
// Try to listen on the port
listener, err := net.Listen("tcp", fmt.Sprintf(":%s", strconv.Itoa(port)))
if err != nil {
// Port is in use
return true
}
// Close listener
defer listener.Close()
return false
}
// Allow port
func AllowPort(port int) (err error) {
// Check if port number is valid
if !IsPort(strconv.Itoa(port)) {
return errors.New("invalid port: " + strconv.Itoa(port))
}
defer func() {
if err == nil {
// Reload firewall
_ = ReloadFirewall()
}
}()
// Command line output
var s string
// Check if it is Ubuntu
if FileExists("/usr/sbin/ufw") || FileExists("/usr/bin/ufw") {
s, err = ExecShell(fmt.Sprintf("ufw allow %d/tcp", port))
if err != nil {
g.Log().Error(context.Background(), "AllowPort error: ", err, " ", s)
}View on GitHub (pinned to fc36c76c05)
Solutions
- Validate the port is an integer in 1-65535 before calling AllowPort.
- Fix the source config or request value that produced the out-of-range port.
- If the caller has a string port, parse with strconv.Atoi and range-check, then surface a friendly validation error to the user.
Example fix
// before
port, _ := strconv.Atoi(req.Port)
public.AllowPort(port) // port==0 -> invalid port: 0
// after
port, err := strconv.Atoi(req.Port)
if err != nil || port < 1 || port > 65535 {
return gerror.Newf("port must be an integer between 1 and 65535, got %q", req.Port)
}
return public.AllowPort(port) Defensive patterns
Strategy: validation
Validate before calling
if port < 1 || port > 65535 {
return fmt.Errorf("port %d out of range 1-65535", port)
}
err := public.AllowPort(port) Type guard
func isValidPort(p int) bool { return p >= 1 && p <= 65535 } Try / catch
if err := public.AllowPort(port); err != nil {
if strings.HasPrefix(err.Error(), "invalid port:") {
return fmt.Errorf("could not open firewall port %d: %w (check your input)", port, err)
}
return err
} Prevention
- Validate ports at the API boundary with a shared validator
- Never ignore errors from strconv.Atoi when parsing port strings
- Persist only validated port values in settings
When it happens
Trigger: Calling AllowPort(port) with port <= 0, port > 65535, or a value IsPort rejects; typically the port came from an unvalidated request parameter or a misconfigured config value parsed from a string.
Common situations: Admin UI submitting an empty/NaN port parsed as 0, config files with port "http" instead of "80", or overflowed values from atoi conversions of large strings.
Related errors
- Add up to 3 URLs
- supplier name, base URL, and API key are required
- invalid base URL format: %w
- base URL must use http or https protocol
- Prefix validation error: %w
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/9d865061624e5c19.
Report an issue: GitHub.