Repository navigation
Conversation
chessing234
left a comment
There was a problem hiding this comment.
please escape the diagnostic before writing it into the wrapper.
| cat >"$HOME/.local/bin/$command" <<EOF | ||
| #!/bin/bash | ||
| if [[ -n \${$guard:-} ]]; then | ||
| echo "omarchy-mise-install: '$command' recursed; mise could not provide $bin_arg" >&2 |
There was a problem hiding this comment.
please quote the generated diagnostic as shell data too: command is inserted raw inside its double-quoted echo, so an accepted literal command name such as tool$(touch marker) runs that substitution when the recursion guard fires. the actual generator and wrapper create the marker in an isolated fixture; the existing %q escaping on the execution lines does not protect this new line.
When a tool is missing or mise fails to provide the requested binary, `mise x <tool> -- <bin>` falls back to searching PATH. Because the wrapper itself lives in `~/.local/bin`, mise finds and re-executes the wrapper, recursing indefinitely and forking thousands of processes until the machine exhausts resources. Emit an environment guard variable (`_OMARCHY_MISE_GUARD_<COMMAND>`) in the generated wrapper script so recursive executions fail fast with exit code 127 instead of hanging the system. Fixes omacom#13177
9fb3bc9 to
8e30031
Compare
|
| cat >"$HOME/.local/bin/$command" <<EOF | ||
| #!/bin/bash | ||
| if [[ -n \${$guard:-} ]]; then | ||
| printf '%s\n' $diagnostic_arg >&2 | ||
| exit 127 | ||
| fi | ||
| export $guard=1 |
There was a problem hiding this comment.
Existing wrappers remain unguarded
This check is written only when omarchy-mise-install generates a wrapper. Updating Omarchy leaves wrappers already installed in ~/.local/bin unchanged, and this PR adds no migration to rewrite them. If an existing wrapper's tool is missing or does not provide its binary, mise x can still find that wrapper through PATH and recurse until the machine exhausts its process limit. Existing wrappers need a rollout path for the guard.
| *) bin_arg="\"$bin\"" ;; | ||
| esac | ||
|
|
||
| guard="_OMARCHY_MISE_GUARD_$(printf '%s' "$command" | tr -c 'A-Za-z0-9_' '_' | tr '[:lower:]' '[:upper:]')" |
There was a problem hiding this comment.
Distinct commands share guards
The accepted command names my-tool and my_tool both produce _OMARCHY_MISE_GUARD_MY_TOOL. If a tool launched by one wrapper invokes the other wrapper through PATH, the second sees the inherited guard and exits 127 instead of running. This can break a valid combination of user-installed tools.
|
Thanks for tackling #13177. The The guard leaks into the real tool's environment.
All of the wrappers in #!/bin/bash
export MISE_MINIMUM_RELEASE_AGE=0
mise use -g --quiet "gh" || exit 1
tool=$(mise which "gh" 2>/dev/null)
if [[ -z $tool || $tool == "$HOME/.local/bin/"* ]]; then
echo "omarchy-mise-install: 'gh' recursed; mise could not provide gh" >&2
exit 127
fi
exec mise x "gh" -- "$tool" "$@"Wrappers that are already installed also need a migration to pick up the fix, as Greptile noted. Note that #9583 and #8692 already propose exec-by-resolved-path. Your later #13614 also moves toward |
|
see #9596, that should be the correct fix |
|
Reviewed at 8e30031 against Two defects in the guard, both visible in the generated wrapper:
Also, #8692 is the oldest of these fixes. It resolves the binary from the package's own The second opinion, Codex Medium, compared the five diffs separately and also recommends #8692. It found the #7234 failure above. Otherwise it agreed with a conclusion already written down, so its independence is not guaranteed. The choice between these pull requests is the maintainer's. This one waits on that decision. |
|
my 2 cents: if we continue adding complex bash to the wrappers we're going to continue to run into edge-cases. mise's lazy tools i built specifically for omarchy to be able to get rid of them and it has non-omarchy users already validating it |
Summary
When a tool is not installed or mise fails to provide the requested binary,
mise x <tool> -- <bin>falls back to searchingPATH. Because the wrapper itself is installed in~/.local/bin, mise re-executes the wrapper script. Without a recursion guard, this creates an unbounded fork loop (~1,000 forks/sec) that saturates the machine until it exhausts process limits.This emits a tool-specific environment guard variable (
_OMARCHY_MISE_GUARD_<COMMAND>) at the top of the generated wrapper so recursive invocations fail fast with exit code 127 and a clear stderr message instead of hanging the machine.Fixes #13177
Testing
test/shell.d/mise-install-test.shwith a test simulatingmise xfalling back toPATHwhen an executable is missing.bash test/shell.d/mise-install-test.sh(all 5 assertions passed).