{"record":{"id":"fb38572b8cc032f8","repo":"netbirdio/netbird","slug":"invalid-source-port-v","errorCode":null,"errorMessage":"invalid source port: %v","messagePattern":"invalid source port: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/cmd/trace.go","lineNumber":55,"sourceCode":"\ttraceCmd.Flags().Bool(\"rst\", false, \"TCP RST flag\")\n\ttraceCmd.Flags().Bool(\"psh\", false, \"TCP PSH flag\")\n\ttraceCmd.Flags().Bool(\"urg\", false, \"TCP URG flag\")\n}\n\nfunc tracePacket(cmd *cobra.Command, args []string) error {\n\tdirection := strings.ToLower(args[0])\n\tif direction != \"in\" && direction != \"out\" {\n\t\treturn fmt.Errorf(\"invalid direction: use 'in' or 'out'\")\n\t}\n\n\tprotocol := cmd.Flag(\"protocol\").Value.String()\n\tif protocol != \"tcp\" && protocol != \"udp\" && protocol != \"icmp\" {\n\t\treturn fmt.Errorf(\"invalid protocol: use tcp/udp/icmp\")\n\t}\n\n\tsport, err := cmd.Flags().GetUint16(\"sport\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid source port: %v\", err)\n\t}\n\tdport, err := cmd.Flags().GetUint16(\"dport\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid destination port: %v\", err)\n\t}\n\n\t// For TCP/UDP, generate random ephemeral port (49152-65535) if not specified\n\tif protocol != \"icmp\" {\n\t\tif sport == 0 {\n\t\t\tsport = uint16(rand.Intn(16383) + 49152)\n\t\t}\n\t\tif dport == 0 {\n\t\t\tdport = uint16(rand.Intn(16383) + 49152)\n\t\t}\n\t}\n\n\tvar tcpFlags *proto.TCPFlags\n\tif protocol == \"tcp\" {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/trace.go#L37-L73","documentation":"Thrown by tracePacket (client/cmd/trace.go:55). cmd.Flags().GetUint16(\"sport\") failed, which cobra/pflag reports when the --sport value cannot be parsed as an unsigned 16-bit integer - non-numeric text or a number outside 0-65535. Note 0 is valid and means 'pick a random ephemeral port'.","triggerScenarios":"'netbird debug trace ... --sport 70000' (above 65535), '--sport -1', or '--sport abc'. Ports are uint16; anything outside [0,65535] or non-numeric fails here.","commonSituations":"Copy-pasting a service name instead of a port; ephemeral-port range math off by one (49152-65535 is the range the tool itself randomizes into); locale/format artifacts in scripts.","solutions":["Pass a decimal port in 0-65535, or omit --sport to let the tool choose a random ephemeral port","If scripting, validate with a bounds check before invoking the CLI"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if v, err := strconv.ParseUint(sportStr, 10, 16); err != nil || v > 65535 {\n    log.Fatalf(\"--sport must be 0-65535, got %q\", sportStr)\n}","typeGuard":"func isValidPort16(s string) bool {\n    v, err := strconv.ParseUint(s, 10, 16)\n    return err == nil // ParseUint(_, 16) already enforces <= 65535\n}","tryCatchPattern":null,"preventionTips":["Pass numeric ports only; 0 means auto-random ephemeral","Validate script variables building the command line"],"tags":["cli","validation","trace","port","user-input","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}