{"record":{"id":"d23da5f39a6883b7","repo":"crowdsecurity/crowdsec","slug":"invalid-ip-address-s-w","errorCode":null,"errorMessage":"invalid ip address '%s': %w","messagePattern":"invalid ip address '(.+?)': %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/types/ip.go","lineNumber":54,"sourceCode":"/*returns a range for any ip or range*/\nfunc Addr2Ints(anyIP string) (int, int64, int64, int64, int64, error) {\n\tif strings.Contains(anyIP, \"/\") {\n\t\t_, net, err := net.ParseCIDR(anyIP)\n\t\tif err != nil {\n\t\t\treturn -1, 0, 0, 0, 0, fmt.Errorf(\"invalid ip range '%s': %w\", anyIP, err)\n\t\t}\n\n\t\treturn Range2Ints(*net)\n\t}\n\n\tip := net.ParseIP(anyIP)\n\tif ip == nil {\n\t\treturn -1, 0, 0, 0, 0, fmt.Errorf(\"invalid ip address '%s'\", anyIP)\n\t}\n\n\tsz, start, end, err := IP2Ints(ip)\n\tif err != nil {\n\t\treturn -1, 0, 0, 0, 0, fmt.Errorf(\"invalid ip address '%s': %w\", anyIP, err)\n\t}\n\n\treturn sz, start, end, start, end, nil\n}\n\n/*size (16|4), nw_start, suffix_start, nw_end, suffix_end, error*/\nfunc Range2Ints(network net.IPNet) (int, int64, int64, int64, int64, error) {\n\tszStart, nwStart, sfxStart, err := IP2Ints(network.IP)\n\tif err != nil {\n\t\treturn -1, 0, 0, 0, 0, fmt.Errorf(\"converting first ip in range: %w\", err)\n\t}\n\n\tlastAddr := LastAddress(network)\n\n\tszEnd, nwEnd, sfxEnd, err := IP2Ints(lastAddr)\n\tif err != nil {\n\t\treturn -1, 0, 0, 0, 0, fmt.Errorf(\"transforming last address of range: %w\", err)\n\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/types/ip.go#L36-L72","documentation":"After net.ParseIP succeeds, Addr2Ints converts the address to integers via IP2Ints; if that conversion fails the error is wrapped as \"invalid ip address '%s': %w\". This indicates a parseable-looking address whose internal conversion failed — rare, typically an unexpected address representation rather than user error.","triggerScenarios":"IP2Ints(ip) returning an error for a parsed address — e.g. an IP form that does not convert to 4 or 16 bytes as expected — during Addr2Ints/NewRange.","commonSituations":"Programmatically constructed net.IP values or unusual textual forms slipping through; upstream data feed delivering addresses that parse but do not convert cleanly; version-dependent ParseIP acceptance changes.","solutions":["Inspect the wrapped error from IP2Ints to see the conversion failure and normalize the input (e.g. ip.String() round-trip) before retrying","Normalize the address with net.ParseIP(s).String() to canonical form before calling Addr2Ints","Ensure the address is a well-formed textual IPv4/IPv6 (not a zone-suffixed or binary form)","If it comes from an external feed, validate/parse at ingestion and reject malformed records early"],"exampleFix":"// before\nr, err := types.NewRange(rawInput)\n// after\ncanonical := net.ParseIP(strings.TrimSpace(rawInput))\nif canonical == nil { return fmt.Errorf(\"not an ip: %s\", rawInput) }\nr, err := types.NewRange(canonical.String())","handlingStrategy":"validation","validationCode":"import \"net\"\nfunc canonicalIP(s string) (string, error) {\n  ip := net.ParseIP(strings.TrimSpace(s))\n  if ip == nil { return \"\", fmt.Errorf(\"not an ip: %q\", s) }\n  return ip.String(), nil\n}","typeGuard":null,"tryCatchPattern":"r, err := types.NewRange(input)\nif err != nil {\n  if strings.Contains(err.Error(), \"invalid ip address\") {\n    if canon, cerr := canonicalIP(input); cerr == nil {\n      r, err = types.NewRange(canon)\n    }\n    if err != nil { return err }\n  } else { return err }\n}","preventionTips":["Round-trip addresses through net.ParseIP(s).String() to canonicalize before conversion","Reject zone-suffixed or non-textual address forms at ingestion","Validate records from external feeds before passing them to Addr2Ints"],"tags":["go","network","ip","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}