Skip to content

Fix has_local to not search PATH for external 'local' command - #5018

Open
harriiinnii wants to merge 1 commit into
rust-lang:mainfrom
harriiinnii:fix/has-local-path-search
Open

Fix has_local to not search PATH for external 'local' command#5018
harriiinnii wants to merge 1 commit into
rust-lang:mainfrom
harriiinnii:fix/has-local-path-search

Conversation

@harriiinnii

Copy link
Copy Markdown

Problem

has_local() in rustup-init.sh is used to detect whether the shell has a builtin local keyword. On shells that lack it, the function falls through and the script aliases local to typeset.

However, if the shell has no builtin local and an executable named local happens to exist somewhere in $PATH, that external command would be found and used instead — making has_local return success incorrectly. Any subsequent local usage would then invoke that external command rather than the typeset alias.

Fix

Set PATH= before the local call inside has_local. This prevents the shell from searching $PATH for a local executable: on shells with a builtin local the call succeeds as before, and on shells without it the call correctly fails even if an external local exists in $PATH.

has_local() {
    # shellcheck disable=SC2034  # deliberately unused
    PATH= local _has_local
}

Fixes #5009

On systems where /bin/sh has no builtin `local`, `has_local` would fall
through and search $PATH for a command named `local`. If such a command
existed there, it would be incorrectly used as the alias target.

Fix by setting PATH= before the `local` call so that $PATH is not
consulted for the fallback, matching the behavior on shells that have a
builtin `local`.

Fixes rust-lang#5009
@rami3l

rami3l commented Aug 17, 2026

Copy link
Copy Markdown
Member

@harriiinnii Oops, it seems like your change is not a pure refactoring step? Would you mind doing some more digging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky has_local in rustup-init.sh

2 participants