affaan-m/ECC · error · Error

--cwd must not contain a NUL byte.

Error message

--cwd must not contain a NUL byte.

What it means

validateCwd rejects any --cwd value containing a NUL (\0) byte. NUL bytes can truncate or corrupt paths at the OS boundary and are a classic injection vector. This is the first of two cwd checks (the second, at line 48, validates absoluteness). It fires during parseArgs.

Source

Thrown at skills/terminal-opener/scripts/open-terminal.js:47

  --help, -h         Show this help.

Always pass the executable and arguments as separate entries after --.
Shell command strings are not accepted.
`;
}

function isAbsolutePath(value) {
  return path.isAbsolute(value) || path.win32.isAbsolute(value);
}

function validateTerminalName(value) {
  if (!/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(value)) {
    throw new Error('Invalid terminal name; use a simple adapter name such as wezterm.');
  }
}

function validateCwd(value) {
  if (value.includes('\0')) throw new Error('--cwd must not contain a NUL byte.');
  if (!isAbsolutePath(value)) throw new Error('--cwd must be an absolute path.');
}

function validateExecutable(value) {
  if (!value || /[\0\r\n]/.test(value)) {
    throw new Error('Executable must be a non-empty argv entry without control bytes.');
  }

  const whitespaceIndex = value.search(/\s/);
  const separatorIndexes = [value.indexOf('/'), value.indexOf('\\')].filter(index => index >= 0);
  const firstSeparatorIndex = separatorIndexes.length > 0 ? Math.min(...separatorIndexes) : -1;
  const resemblesExecutablePath = isAbsolutePath(value)
    || (firstSeparatorIndex >= 0 && (whitespaceIndex < 0 || firstSeparatorIndex < whitespaceIndex));

  if (whitespaceIndex >= 0 && !resemblesExecutablePath) {
    throw new Error(
      'Executable must be one argv entry, not an interpolated shell command string.'
    );

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Sanitize the cwd string: strip NUL bytes before passing.
  2. Source --cwd from a trusted, validated path rather than raw external input.

Example fix

// before
const cwd = untrustedInput; // may contain \0
parseArgs(['--cwd', cwd, '--', 'echo']);

// after
const cwd = untrustedInput.replace(/\0/g, '');
parseArgs(['--cwd', cwd, '--', 'echo']);
Defensive patterns

Strategy: validation

Validate before calling

function safeCwd(value) {
  if (typeof value !== 'string' || value.includes('\0')) {
    throw new Error('cwd contains a NUL byte or is not a string');
  }
  return value;
}

Prevention

When it happens

Trigger: Passing --cwd with a value that includes a literal \0 byte. parseArgs calls validateCwd before returning.

Common situations: Corrupted environment or argv; malicious or untrusted input forwarded into --cwd; binary garbage in a path variable.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/74d1c7872ee6aa2c. Report an issue: GitHub.