{"record":{"id":"bde61bafd3baec01","repo":"owasp-amass/amass","slug":"failed-to-parse-s-as-a-cidr","errorCode":null,"errorMessage":"failed to parse %s as a CIDR","messagePattern":"failed to parse (.+?) as a CIDR","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/afmt/parse.go","lineNumber":171,"sourceCode":"\t\tif i > 0 {\n\t\t\tbuilder.WriteRune(',')\n\t\t}\n\t\tbuilder.WriteString(ipnet.String())\n\t}\n\treturn builder.String()\n}\n\n// Set implements the flag.Value interface.\nfunc (p *ParseCIDRs) Set(s string) error {\n\tif s == \"\" {\n\t\treturn fmt.Errorf(\"%s is not a valid CIDR\", s)\n\t}\n\n\tcidrs := strings.Split(s, \",\")\n\tfor _, cidr := range cidrs {\n\t\t_, ipnet, err := net.ParseCIDR(cidr)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse %s as a CIDR\", cidr)\n\t\t}\n\n\t\t*p = append(*p, ipnet)\n\t}\n\treturn nil\n}\n\nfunc (p *ParseASNs) String() string {\n\tif p == nil {\n\t\treturn \"\"\n\t}\n\tvar builder strings.Builder\n\tfor i, n := range *p {\n\t\tif i > 0 {\n\t\t\tbuilder.WriteRune(',')\n\t\t}\n\t\tbuilder.WriteString(strconv.Itoa(n))\n\t}","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/afmt/parse.go#L153-L189","documentation":"Within ParseCIDRs.Set, each comma-separated token is parsed with net.ParseCIDR. A token that is not valid CIDR notation (address plus /prefix length) aborts parsing with this per-token error, distinguishing bad entries from the empty-string case handled elsewhere.","triggerScenarios":"Tokens missing a prefix (\"192.168.1.1\"), out-of-range prefixes (\"10.0.0.0/33\"), double slashes (\"10.0.0.0/8/8\"), or non-numeric garbage in the prefix position.","commonSituations":"Forgetting the /prefix on a bare IP, typo'd prefix lengths, IPv6/IPv4 prefix confusion, copy-paste artifacts like spaces or trailing commas.","solutions":["Ensure every entry is in x.x.x.x/nn form, e.g. \"192.168.1.0/24\".","Validate locally with net.ParseCIDR (or an equivalent ipaddress library) before passing the flag.","Check prefix bounds: 0-32 for IPv4, 0-128 for IPv6."],"exampleFix":"// before\n-cidr \"192.168.1.1\"          # missing prefix -> failed to parse as a CIDR\n// after\n-cidr \"192.168.1.0/24\"       # network address with prefix length","handlingStrategy":"validation","validationCode":"func eachTokenIsCIDR(value string) error {\n\tfor _, c := range strings.Split(value, \",\") {\n\t\tif _, _, err := net.ParseCIDR(strings.TrimSpace(c)); err != nil {\n\t\t\treturn fmt.Errorf(\"%q is not CIDR notation (need address/prefix)\", c)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":"func isCIDRToken(s string) bool { _, _, err := net.ParseCIDR(s); return err == nil }","tryCatchPattern":null,"preventionTips":["Always include a /prefix on every CIDR entry.","Check prefix length bounds (0-32 IPv4, 0-128 IPv6) before passing.","Trim whitespace and deduplicate tokens before building the flag."],"tags":["cli","flag-parsing","cidr","network"],"backgroundTag":"invalid-flag-value","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}