Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty lines in /etc/paths.d cause . to appear in PATH on macOS Mojave #5809

Closed
strayer opened this issue Apr 11, 2019 · 7 comments
Closed

Empty lines in /etc/paths.d cause . to appear in PATH on macOS Mojave #5809

strayer opened this issue Apr 11, 2019 · 7 comments
Labels
bug
Milestone

Comments

@strayer
Copy link

@strayer strayer commented Apr 11, 2019

I recently discovered that my PATH contains a . between the default paths of macOS from /etc/paths*:

sh-3.2$ sh -c 'env HOME=$(mktemp -d) /usr/local/bin/fish'
Welcome to fish, the friendly interactive shell
strayer@wolf359 /U/s/.config> echo $PATH
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/X11/bin /Applications/VMware Fusion.app/Contents/Public /Library/TeX/texbin . /Applications/Wireshark.app/Contents/MacOS
strayer@wolf359 /U/s/.config> echo $fish_user_paths

One of the files in /etc/paths.d contains empty lines (/etc/paths.d/TeX to be specific):

strayer@wolf359 /U/s/.config> cat /etc/paths /etc/paths.d/*
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/Applications/VMware Fusion.app/Contents/Public/Library/TeX/texbin


/Applications/Wireshark.app/Contents/MacOS

When I manually remove these empty lines, the dot doesn't appear in PATH anymore:

sh-3.2$ sh -c 'env HOME=$(mktemp -d) /usr/local/bin/fish'
Welcome to fish, the friendly interactive shell
strayer@wolf359 /U/s/.config> echo $PATH
/usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/X11/bin /Applications/VMware Fusion.app/Contents/Public /Library/TeX/texbin /Applications/Wireshark.app/Contents/MacOS

fish version, installed via Homebrew:

strayer@wolf359 ~> fish --version
fish, version 3.0.2
strayer@wolf359 ~> echo $version
3.0.2

TERM: xterm-256color
macOS Mojave 10.14.4 (18E226)
Terminal: iTerm2 Build 3.3.0beta2

@floam floam added the bug label Apr 11, 2019
@floam
Copy link
Member

@floam floam commented Apr 11, 2019

Can reproduce.

@floam
Copy link
Member

@floam floam commented Apr 11, 2019

There is a small problem with the logic causing empty elements to be put into $PATH for empty lines. And I did not know this until now but we translate these to . on purpose.

/// Ensure the content of the magic path env vars is reasonable. Specifically, that empty path
/// elements are converted to explicit "." to make the vars easier to use in fish scripts.
static void init_path_vars() {
    // Do not replace empties in MATHPATH - see #4158.
    fix_colon_delimited_var(L"PATH", env_stack_t::globals());
    fix_colon_delimited_var(L"CDPATH", env_stack_t::globals());
}

@floam
Copy link
Member

@floam floam commented Apr 11, 2019

I don't understand this business of sticking . into $PATH or $CDPATH here.. for the sake of aiding fish scripting? What am I not getting? If someone prepended an empty component to $PATH, they'd be in a potentially dangerous situation when in a directory with unfortunately-named binaries.

@floam
Copy link
Member

@floam floam commented Apr 11, 2019

Oh, I didn't realize that empty $PATH components usually are equivalent to . in most shells.

@faho
Copy link
Member

@faho faho commented Apr 11, 2019

Does the official path_helper thing handle this in the same way?

@floam
Copy link
Member

@floam floam commented Apr 11, 2019

Yes. Blank lines are ignored.

@floam
Copy link
Member

@floam floam commented Apr 11, 2019

path_helper.c

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug
Projects
None yet
Development

No branches or pull requests

3 participants