-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Labels
Description
open()
with O_DIRECTORY
as used by opendir()
leaks a file descriptor if the filename is not a directory (ENOTDIR
).
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.2 (a77b559a8b40b7e89fc8c17e41034128df9543e4)
clang version 14.0.0 (https://github.com/llvm/llvm-project 782c0dd1a1c235afb09a34e7da4a1267ead14765)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
reproducer
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#define FNAME "/etc/passwd"
#define LOOP 10000
int main(void) {
int fd;
for (int i=0; i < LOOP; i++) {
fprintf(stderr, "%i\n", i);
fd = open(FNAME, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
assert(fd < 0);
if (errno != ENOTDIR) {
perror("open O_DIRECTORY failed");
return 1;
}
}
return 0;
}
$ emcc -s NODERAWFS -o dirfdleak.js dirfdleak.c
$ node dirfdleak.js
...
open O_DIRECTORY failed: No file descriptors available