Skip to content

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

Closed
@mstewartgallus

Description

@mstewartgallus

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions