Skip to content

File descriptor closing in spawn_process_os in libnative on Unix platforms misses file descriptors opened before lowered resource limits #13790

New issue

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

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

Already on GitHub? # to your account

Closed
mstewartgallus opened this issue Apr 27, 2014 · 1 comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

Comments

@mstewartgallus
Copy link
Contributor

File descriptor closing in spawn_process_os in libnative on Unix platforms misses file descriptors opened before lowered resource limits.

The code is here: https://github.com/mozilla/rust/blob/master/src/libnative/io/process.rs#L581.

I know on BSD one can use closefrom and on Linux one can use /proc/self/fd.

The following code demonstrates how a file can be carried in over lowered resource limits.

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>

int main() {
    struct rlimit const limit = {
        .rlim_cur = 0,
        .rlim_max = 0
    };
    if (-1 == setrlimit(RLIMIT_NOFILE, &limit)) {
        fprintf(stderr, "error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    puts("Printing to standard output even though the resource limit is lowered past standard output's number!");

    return EXIT_SUCCESS;
}
@alexcrichton
Copy link
Member

Closing as a dupe of #12148.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows
Projects
None yet
Development

No branches or pull requests

2 participants