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

env::vars panics if environ is null #53200

Closed
jorickert opened this issue Aug 8, 2018 · 1 comment
Closed

env::vars panics if environ is null #53200

jorickert opened this issue Aug 8, 2018 · 1 comment
Labels
C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jorickert
Copy link

jorickert commented Aug 8, 2018

The following code panics:

unsafe { libc::clearenv(); };
assert_eq!(env::vars().count(), 0);

The problem is that env assumes that environ is not null. See Rust env implementation

The clearenv(3 ) function on linux is often implemented by freeing environ and setting it to null. See uclibc and glibc

In my opinion the stdlib could handle this more gracefully and return an empty iterator instead of panicking

@kennytm kennytm added O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Aug 8, 2018
@BurntPizza
Copy link
Contributor

I'm working on a PR.

BurntPizza added a commit to BurntPizza/rust that referenced this issue Aug 9, 2018
kennytm added a commit to kennytm/rust that referenced this issue Aug 11, 2018
… r=alexcrichton

Don't panic on std::env::vars() when env is null.

Fixes rust-lang#53200.

Reviewer(s):
* Do I need to do any `#[cfg()]` here?
* Is this use of libc ok for a dev-dependency?
kennytm added a commit to kennytm/rust that referenced this issue Aug 13, 2018
… r=alexcrichton

Don't panic on std::env::vars() when env is null.

Fixes rust-lang#53200.

Reviewer(s):
* Do I need to do any `#[cfg()]` here?
* Is this use of libc ok for a dev-dependency?
kennytm added a commit to kennytm/rust that referenced this issue Aug 14, 2018
… r=alexcrichton

Don't panic on std::env::vars() when env is null.

Fixes rust-lang#53200.

Reviewer(s):
* Do I need to do any `#[cfg()]` here?
* Is this use of libc ok for a dev-dependency?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants