{"record":{"id":"4fcce9a08ab4cb83","repo":"docker/cli","slug":"invalid-argument-w","errorCode":null,"errorMessage":"invalid argument: %w","messagePattern":"invalid argument: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/connhelper/ssh/ssh.go","lineNumber":172,"sourceCode":"\tremoteCommand, err := quoteCommand(remoteCommandAndArgs...)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif remoteCommand != \"\" {\n\t\tsshArgs = append(sshArgs, remoteCommand)\n\t}\n\treturn sshArgs, nil\n}\n\n// quoteCommand returns the remote command to run using the ssh connection\n// as a single string, quoting values where needed because ssh executes\n// these in a POSIX shell.\nfunc quoteCommand(commandAndArgs ...string) (string, error) {\n\tvar quotedCmd string\n\tfor i, arg := range commandAndArgs {\n\t\ta, err := syntax.Quote(arg, syntax.LangPOSIX)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"invalid argument: %w\", err)\n\t\t}\n\t\tif i == 0 {\n\t\t\tquotedCmd = a\n\t\t\tcontinue\n\t\t}\n\t\tquotedCmd += \" \" + a\n\t}\n\t// each part is quoted appropriately, so now we'll have a full\n\t// shell command to pass off to \"ssh\"\n\treturn quotedCmd, nil\n}\n","sourceCodeStart":154,"sourceCodeEnd":184,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/connhelper/ssh/ssh.go#L154-L184","documentation":"Returned by ssh.Spec.Command() when a remote-command argument cannot be safely quoted for execution in a POSIX shell on the remote host. The wrapped error is a *syntax.QuoteError (mvdan.cc/shell quoting). The POSIX variant has no escape sequences for non-printable runes, and no variant can represent a NUL byte, so such input is rejected to avoid emitting an invalid or unsafe shell command. Note: Spec.Args() swallows this error (returns nil args); only Command() surfaces it.","triggerScenarios":"Calling spec.Command(sshFlags, remoteCommandAndArgs...) where one of remoteCommandAndArgs contains a NUL byte (\\x00), a non-printable/control rune (e.g. bell \\x07, ESC \\x1b), invalid UTF-8 (utf8.RuneError), or a codepoint > utf8.MaxRune. The package always uses LangPOSIX, under which any non-printable rune is fatal.","commonSituations":"Passing binary/blob payloads as a literal command argument; embedding ANSI/terminal escape sequences; reading args from env vars, files, or sockets that may carry control characters; garbled/mojibake input piped into the helper.","solutions":["Sanitize each argument: reject or strip NUL bytes and non-printable control characters before calling Command.","Transmit binary data via stdin or a remote file path instead of as a positional command argument.","Validate that each arg is valid UTF-8 containing only printable runes (unicode.IsPrint) before use."],"exampleFix":"// before\ncmd, err := spec.Command(flags, userInput)\n// userInput may contain control chars / NUL -> \"invalid argument\"\n\n// after\nfor _, a := range userInput {\n    if !isPrintableSafe(a) {\n        return fmt.Errorf(\"unsafe argument %q\", a)\n    }\n}\ncmd, err := spec.Command(flags, userInput)","handlingStrategy":"validation","validationCode":"// isSafeSSHArg reports whether s can be POSIX-quoted by the ssh helper.\nfunc isSafeSSHArg(s string) bool {\n    for _, r := range s {\n        if r == 0 || r == utf8.RuneError || !unicode.IsPrint(r) {\n            return false\n        }\n    }\n    return utf8.ValidString(s)\n}\n\nfor _, a := range args {\n    if !isSafeSSHArg(a) {\n        return fmt.Errorf(\"argument contains non-quotable characters\")\n    }\n}\ncmd, err := spec.Command(flags, args...)","typeGuard":null,"tryCatchPattern":"var quoteErr *syntax.QuoteError\nif errors.As(err, &quoteErr) {\n    // an argument could not be shell-quoted; sanitize input and retry, or reject\n}","preventionTips":["Never pass binary data as a positional ssh command argument; stream it via stdin.","Validate user-derived args with unicode.IsPrint and reject NUL/invalid UTF-8 before calling Command.","Remember Spec.Args() silently drops the command on a quoting failure — prefer Command() if you need the error."],"tags":["ssh","shell-quoting","validation","posix","connhelper"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}