A toolchain whose path has a space or a shell metacharacter cannot be used: the compiler and llvm-ar go into shell commands unquoted #56

Open
opened 2026-11-27 18:28:25 +00:00 by jorijnvdgraaf · 0 comments

Summary

crafter-build runs its commands through sh, and puts the toolchain's own programs into some of them quoted and into others as they stand. Where the toolchain's directory has a space, or a character the shell interprets, the first unquoted command, a probe GetToolchain() runs, already fails, and nothing builds. CRAFTER_BUILD_LLVM_DIR can name such a directory, and so can a toolchain installed beside crafter-build:

$ CRAFTER_BUILD_LLVM_DIR='/opt/llvm dir' crafter-build --version
...
compiler: could not run /opt/llvm dir/bin/clang++ (exit 127): sh: line 1: /opt/llvm: No such file or directory
$ CRAFTER_BUILD_LLVM_DIR='/opt/llvm dir' crafter-build
could not run /opt/llvm dir/bin/clang++ (exit 127): sh: line 1: /opt/llvm: No such file or directory

The toolchain goes into a command unquoted in:

  • GetToolchain()'s three probes, -print-target-triple, --version and -no-canonical-prefixes --version (implementations/Crafter.Build-Toolchain.cpp:412, :428, :434);
  • ClangResourceDir(), lint's -print-resource-dir (implementations/Crafter.Build-Lint.cpp:718);
  • GetBaseCommand(), the first word of every compile command, of the std module's, of the host PCM cache's and of project.cpp's own (implementations/Crafter.Build-Platform.cpp:994);
  • the archive step, llvm-ar and the archive's path (implementations/Crafter.Build-Clang.cpp:2014).

It is quoted, with ShellQuote, by the scan, for the scanner and the compiler the scan is given (implementations/Crafter.Build-Clang.cpp:1179); by the Flatpak packager, for the compiler's -print-file-name and for llvm-readelf (implementations/Crafter.Build-Flatpak.cpp:215, :226); and by the CMake externals, for CMAKE_C_COMPILER and CMAKE_CXX_COMPILER (implementations/Crafter.Build-External.cpp:135-136).

The compile command carries other paths unquoted too, the std module's and the configuration's PCM directories (-fprebuilt-module-path) and the sysroot (implementations/Crafter.Build-Clang.cpp:665, :668), and the comment on CommandToArgs takes that as known: "the build assembles and runs this very string through a shell, so a path containing a space is already unsupported upstream of here" (implementations/Crafter.Build-Lint.cpp:358-361). Nothing tells the user, though: the message above is the shell's.

Reproduced with cb8914d (6.4.3) built natively, CRAFTER_BUILD_LLVM_DIR naming a directory with a space whose bin/ links to the system's clang++, clang, llvm-ar, llvm-readelf and clang-scan-deps. Found by the pre-push review of 6.4.3.

Line numbers refer to cb8914d (6.4.3).

Proposal

Quote every path the commands carry, as the scan, the packager and the CMake externals already do. Or refuse a toolchain or project path that the shell would split or interpret, where the Toolchain and the configuration are resolved, with a message that says why.

## Summary crafter-build runs its commands through `sh`, and puts the toolchain's own programs into some of them quoted and into others as they stand. Where the toolchain's directory has a space, or a character the shell interprets, the first unquoted command, a probe `GetToolchain()` runs, already fails, and nothing builds. `CRAFTER_BUILD_LLVM_DIR` can name such a directory, and so can a toolchain installed beside crafter-build: ``` $ CRAFTER_BUILD_LLVM_DIR='/opt/llvm dir' crafter-build --version ... compiler: could not run /opt/llvm dir/bin/clang++ (exit 127): sh: line 1: /opt/llvm: No such file or directory $ CRAFTER_BUILD_LLVM_DIR='/opt/llvm dir' crafter-build could not run /opt/llvm dir/bin/clang++ (exit 127): sh: line 1: /opt/llvm: No such file or directory ``` The toolchain goes into a command unquoted in: - `GetToolchain()`'s three probes, `-print-target-triple`, `--version` and `-no-canonical-prefixes --version` (`implementations/Crafter.Build-Toolchain.cpp:412`, `:428`, `:434`); - `ClangResourceDir()`, lint's `-print-resource-dir` (`implementations/Crafter.Build-Lint.cpp:718`); - `GetBaseCommand()`, the first word of every compile command, of the std module's, of the host PCM cache's and of project.cpp's own (`implementations/Crafter.Build-Platform.cpp:994`); - the archive step, llvm-ar and the archive's path (`implementations/Crafter.Build-Clang.cpp:2014`). It is quoted, with `ShellQuote`, by the scan, for the scanner and the compiler the scan is given (`implementations/Crafter.Build-Clang.cpp:1179`); by the Flatpak packager, for the compiler's `-print-file-name` and for llvm-readelf (`implementations/Crafter.Build-Flatpak.cpp:215`, `:226`); and by the CMake externals, for `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` (`implementations/Crafter.Build-External.cpp:135-136`). The compile command carries other paths unquoted too, the std module's and the configuration's PCM directories (`-fprebuilt-module-path`) and the sysroot (`implementations/Crafter.Build-Clang.cpp:665`, `:668`), and the comment on `CommandToArgs` takes that as known: "the build assembles and runs this very string through a shell, so a path containing a space is already unsupported upstream of here" (`implementations/Crafter.Build-Lint.cpp:358-361`). Nothing tells the user, though: the message above is the shell's. Reproduced with `cb8914d` (6.4.3) built natively, `CRAFTER_BUILD_LLVM_DIR` naming a directory with a space whose `bin/` links to the system's clang++, clang, llvm-ar, llvm-readelf and clang-scan-deps. Found by the pre-push review of 6.4.3. Line numbers refer to `cb8914d` (6.4.3). ## Proposal Quote every path the commands carry, as the scan, the packager and the CMake externals already do. Or refuse a toolchain or project path that the shell would split or interpret, where the Toolchain and the configuration are resolved, with a message that says why.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Build#56
No description provided.