-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
libstd
trusts environment variables too much
#40320
Comments
It is not libstd trusting its environment too much. It is your environment being misconfigured, regardless of it being a common practice or not. (Also, |
@nagisa The fallback seems to me like it is trying to avoid exactly this situation. The issue I have now is that I have to scroll every time through Rust's I hit this issue when I tried in my library to obtain the user's I think I understand from what point of view you are coming. My point of view is: |
Okay, so this issue is valid for at least
but only for Windows.we probably should unify the behaviour docs between window and unix here. So this is not your average “I dislike its semantics” bug, but “it does not work as documented” one and is therefore much more severe than initially seemed to me. |
@nagisa I think that what the documentation says does not make the behavior correct. |
@lilianmoraru read what the documentation says again, please. |
@nagisa The documentation implies that before returning I understand that either the docs or the code is wrong here. But, my point is that I am not sure that the environment variable should be read at all when you have access to OS syscalls, but at the same time, |
I propose that we keep doing the same as the platform-specific tools. |
Python stdlib is doing the same as we do on non-Windows (haven't checked the Windows code path, it's in the same file). |
libstd
trusts environment variables to much libstd
trusts environment variables too much
AFAICT, the behavior as it stands for temp_dir and home_dir is the one we want based on a re-read of this issue so I'm going to close, but if I've misread something please leave a comment with the specific problem I missed. :) |
I have not reviewed all the code(I needed specifically only these 2 functions) but at least
home_dir()
andtemp_dir()
are affected by this issue.Let's take
temp_dir
as an example here.It relies on the
TMPDIR
variable to be defined, otherwise it falls back to/tmp
(not on Android).My machine is on Linux and
TMPDIR
is not defined, which means thatRust
falls back to/tmp
, which is OK.The issue is that if I do:
export TMPDIR
- nowtemp_dir
will reliably returnPathBuf::from("")
.Same goes for
export HOME
->home_dir
->Some(PathBuf::from(""))
.As an example: it's not unusual for a bare-bones Linux container to have
HOME
undefined or just set toexport HOME=
.I think that all the functions that have a fallback when an environment variable is not defined, should check if the string is not empty - if it is, then the functions should use the same fallback.
Pinging @alexcrichton
The text was updated successfully, but these errors were encountered: