{"record":{"id":"7c38b05ef892a386","repo":"shadow1ng/fscan","slug":"fscan-invalid-port-d","errorCode":null,"errorMessage":"fscan: invalid port %d","messagePattern":"fscan: invalid port (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/fscan/scanner.go","lineNumber":354,"sourceCode":"\t}\n\tfor _, name := range normalizePlugins(config.Plugins) {\n\t\tif !plugins.Exists(name) {\n\t\t\treturn fmt.Errorf(\"fscan: plugin %q not found\", name)\n\t\t}\n\t\tif !config.AllowUnsafePlugins && !IsSafePlugin(name) {\n\t\t\treturn fmt.Errorf(\"fscan: plugin %q is not enabled for embedded safe mode\", name)\n\t\t}\n\t}\n\tfor _, target := range targets {\n\t\tif strings.TrimSpace(target.Host) == \"\" && strings.TrimSpace(target.URL) == \"\" {\n\t\t\treturn fmt.Errorf(\"fscan: target host or URL is required\")\n\t\t}\n\t\tif strings.TrimSpace(target.Host) != \"\" && strings.TrimSpace(target.URL) != \"\" {\n\t\t\treturn fmt.Errorf(\"fscan: target cannot set both Host and URL\")\n\t\t}\n\t\tfor _, port := range target.Ports {\n\t\t\tif port < 1 || port > 65535 {\n\t\t\t\treturn fmt.Errorf(\"fscan: invalid port %d\", port)\n\t\t\t}\n\t\t}\n\t}\n\tfor _, port := range config.Ports {\n\t\tif port < 1 || port > 65535 {\n\t\t\treturn fmt.Errorf(\"fscan: invalid port %d\", port)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc buildFlagVars(config Config, target Target) *common.FlagVars {\n\ttimeout := secondsOrDefault(config.Timeout, common.DefaultTimeout)\n\twebTimeout := secondsOrDefault(config.WebTimeout, 5)\n\n\tthreadNum := config.Threads\n\tif threadNum <= 0 {\n\t\tthreadNum = common.DefaultThreadNum","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/pkg/fscan/scanner.go#L336-L372","documentation":"This is the per-target port validation branch of validateConfig: every port in Target.Ports must be an integer between 1 and 65535. A port outside that range is not a valid TCP port, so the library refuses to build the fscan flag variables and returns this error before scanning.","triggerScenarios":"A Target in config.Targets has a Ports entry of 0, negative, or > 65535 when ValidateConfig or scanEach runs.","commonSituations":"Zero-value int used as a placeholder port; parsing port strings like '70000' or '-1' from CLI/config without range checks; accidental off-by-one where a count (e.g. 65536) was stored instead of the max port.","solutions":["Clamp or reject the offending port at config load time: keep only values in 1-65535.","Fix the source data (config file, CLI flag, inventory feed) that produced the out-of-range value.","If 0 means 'default port', replace it with an explicit default (e.g. 80) before building the Target.","Validate the whole Targets slice with your own loop before calling ValidateConfig to get a better error message."],"exampleFix":"// before\ntarget.Ports = []int{80, 0, 8080}\n// after\nfor _, p := range rawPorts {\n    if p >= 1 && p <= 65535 {\n        target.Ports = append(target.Ports, p)\n    }\n}","handlingStrategy":"validation","validationCode":"func validPorts(ps []int) bool {\n    for _, p := range ps {\n        if p < 1 || p > 65535 { return false }\n    }\n    return true\n}","typeGuard":"func isValidPort(p int) bool { return p >= 1 && p <= 65535 }","tryCatchPattern":"if err := fscan.ValidateConfig(cfg); err != nil {\n    var perr *strconv.NumError // if ports parsed from strings\n    if strings.Contains(err.Error(), \"invalid port\") {\n        log.Printf(\"bad port in target config: %v\", err)\n    }\n    return err\n}","preventionTips":["Parse port strings with strconv.Atoi and range-check immediately.","Never use 0 as a placeholder port; omit the entry instead.","Centralize port parsing in one validated helper."],"tags":["fscan","validation","ports"],"backgroundTag":"value-out-of-range","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}