Skip to content

env::vars panics if environ is null #53200

Closed
@jorickert

Description

@jorickert

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-linuxOperating system: LinuxT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions