{"record":{"id":"246bb7c36f031d10","repo":"ginuerzh/gost","slug":"invalid-port-s","errorCode":null,"errorMessage":"invalid port: %s","messagePattern":"invalid port: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"permissions.go","lineNumber":40,"sourceCode":"\tMin, Max int\n}\n\n// ParsePortRange parses the s to a PortRange.\n// The s may be a '*' means 0-65535.\nfunc ParsePortRange(s string) (*PortRange, error) {\n\tif s == \"*\" {\n\t\treturn &PortRange{Min: 0, Max: 65535}, nil\n\t}\n\n\tminmax := strings.Split(s, \"-\")\n\tswitch len(minmax) {\n\tcase 1:\n\t\tport, err := strconv.Atoi(s)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif port < 0 || port > 65535 {\n\t\t\treturn nil, fmt.Errorf(\"invalid port: %s\", s)\n\t\t}\n\t\treturn &PortRange{Min: port, Max: port}, nil\n\tcase 2:\n\t\tmin, err := strconv.Atoi(minmax[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tmax, err := strconv.Atoi(minmax[1])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\trealmin := maxint(0, minint(min, max))\n\t\trealmax := minint(65535, maxint(min, max))\n\n\t\treturn &PortRange{Min: realmin, Max: realmax}, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid range: %s\", s)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/permissions.go#L22-L58","documentation":"ParsePortRange parses a port spec; the single-value branch parses with strconv.Atoi and then range-checks 0–65535. A syntactically valid integer outside that range (or causing Atoi failure, which surfaces strconv's own error) yields \"invalid port: %s\" for out-of-range values.","triggerScenarios":"Calling ParsePortRange(\"70000\"), ParsePortRange(\"-5\"), or any single token whose numeric value is <0 or >65535; also reached via ParsePortSet for such elements.","commonSituations":"Config typos in port-based permissions (e.g. port \"65536\", \"99999\"); generated configs with unvalidated user input; mixing port ranges with negative numbers.","solutions":["Correct the port value to be within 0–65535 in the config/permission string.","Validate ports with a quick pre-check (parse and range-check) before passing to ParsePortSet/ParsePermissions.","If the input came from user input, clamp or reject it at your application's validation layer."],"exampleFix":"// before\nperms = \"connect * * 65536\"\n// after\nperms = \"connect * * 65535\"","handlingStrategy":"validation","validationCode":"func validPort(s string) bool {\n    p, err := strconv.Atoi(s)\n    return err == nil && p >= 0 && p <= 65535\n}\nif !validPort(portSpec) { return errors.New(\"port out of range\") }","typeGuard":null,"tryCatchPattern":"pr, err := ParsePortRange(spec)\nif err != nil {\n    return fmt.Errorf(\"bad port spec %q: %w\", spec, err)\n}","preventionTips":["Range-check ports 0–65535 in config loaders","Reject negative or oversized values early","Unit-test permission strings before deploy"],"tags":["validation","ports","permissions"],"backgroundTag":"invalid-port-range","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}