Skip to content

Commit 336166d

Browse files
committed
vfs: keep default dlopen flags for real file paths
The dlopen hook installed while a VFS is mounted always forwarded its flags parameter, so a two-argument process.dlopen() call for a real file system path reached the original implementation with `undefined` as the flags. That coerces to 0, which is not a valid dlopen(2) mode, instead of applying the default flags, and loading any addon from the real file system failed with EINVAL while a VFS was mounted. Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 2987a59 commit 336166d

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎lib/internal/vfs/setup.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,10 @@ function installAddonLoader() {
968968
const { dlopenBinary } = internalBinding('process_methods');
969969
return dlopenBinary(module, filename, flags, readFileSync(filename));
970970
}
971+
// Do not forward a missing flags argument as `undefined`:
972+
// process.dlopen() coerces it to 0, which is not a valid dlopen(2)
973+
// mode, instead of applying the default flags.
974+
if (flags === undefined) return originalDlopen(module, filename);
971975
return originalDlopen(module, filename, flags);
972976
};
973977
}

‎test/parallel/test-vfs-addon.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ if (process.platform !== 'win32') {
3434
assert.deepStrictEqual(leaked, [], `addon temp not cleaned up: ${leaked}`);
3535
}
3636

37+
// Regression check: while a VFS is mounted, process.dlopen() of a
38+
// real-file-system addon without a flags argument must keep the default
39+
// flags rather than forwarding `undefined`, which coerces to 0 - not a
40+
// valid dlopen(2) mode.
41+
const realMod = { exports: {} };
42+
process.dlopen(realMod, addonPath);
43+
assert.strictEqual(realMod.exports.hello(), 'world');
44+
3745
myVfs.unmount();

0 commit comments

Comments
 (0)