kgretzky/evilginx2 · error

invalid command line string

Error message

invalid command line string

What it means

Parse tokenizes a shell-like command line string into arguments and throws this error when the input ends while the parser is still inside an unterminated escape sequence or quoted section. The library rejects such input because the intended argument boundaries are ambiguous, so it cannot return a faithful argv slice. It is raised at the very end of tokenization, after all characters have been consumed.

Source

Thrown at parser/parser.go:85

			if !doubleQuoted {
				if singleQuoted {
					got = true
				}
				singleQuoted = !singleQuoted
				continue
			}
		}

		got = true
		buf += string(r)
	}

	if got {
		args = append(args, buf)
	}

	if escaped || singleQuoted || doubleQuoted {
		return nil, errors.New("invalid command line string")
	}

	return args, nil
}

func Parse(line string) ([]string, error) {
	return NewParser().Parse(line)
}

View on GitHub (pinned to 4c0988a1d9)

Solutions

  1. Check the input line for a matching closing quote for every opening single/double quote and re-run Parse
  2. Remove or double-escape trailing backslashes before the end of the line
  3. If the line comes from a file (importParamsFromFile), inspect the offending line in the file and fix quoting there
  4. Wrap quotes properly when building commands programmatically, e.g. use strconv.Quote or shell-quoting helpers

Example fix

// before
args, err := parser.Parse("proxy 80 'phish.example.com)")
// after
args, err := parser.Parse("proxy 80 'phish.example.com'")
Defensive patterns

Strategy: validation

Validate before calling

func isBalancedLine(line string) bool {
    var sq, dq bool
    for i := 0; i < len(line); i++ {
        c := line[i]
        if c == '\\' { i++; continue }
        if c == '\'' && !dq { sq = !sq }
        if c == '"' && !sq { dq = !dq }
    }
    return !sq && !dq
}
if !isBalancedLine(line) { /* reject before Parse */ }

Type guard

func parseSafe(line string) ([]string, error) {
    if !isBalancedLine(line) {
        return nil, fmt.Errorf("unbalanced quotes in line: %q", line)
    }
    return parser.Parse(line)
}

Try / catch

args, err := parser.Parse(line)
if err != nil {
    if err.Error() == "invalid command line string" {
        log.Printf("quoting problem in line: %q", line)
        return
    }
    return err
}

Prevention

When it happens

Trigger: Calling Parse (directly or via DoWork / importParamsFromFile) with a line containing a backslash at end of input (dangling escape), an opening single quote without a closing one (e.g. "foo 'bar"), or an opening double quote without a closing one (e.g. "say \"hello").

Common situations: Users pasting commands from documentation where quotes were mangled; programmatically built command lines with unescaped quotes in URLs or hostnames; editing a config/script and accidentally deleting a closing quote; copy-paste truncation of long lines.

Related errors


AI-assisted analysis of kgretzky/evilginx2@4c0988a1d9 (2026-09-05). Data as JSON: /api/errors/382dbb1ae141d41d. Report an issue: GitHub.