test: introduce common.runWithInvalidFD()
This provides a more reliable way to get a fd that can be used to tirgger EBADF. PR-URL: https://github.com/nodejs/node/pull/18864 Fixes: https://github.com/nodejs/node/issues/18820 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
13637d23f7
commit
acf2fd39f7
@ -139,6 +139,14 @@ consisting of all `ArrayBufferView` and an `ArrayBuffer`.
|
||||
|
||||
Returns the file name and line number for the provided Function.
|
||||
|
||||
### runWithInvalidFD(func)
|
||||
* `func` [<Function>]
|
||||
|
||||
Runs `func` with an invalid file descriptor that is an unsigned integer and
|
||||
can be used to trigger `EBADF` as the first argument. If no such file
|
||||
descriptor could be generated, a skip message will be printed and the `func`
|
||||
will not be run.
|
||||
|
||||
### globalCheck
|
||||
* [<boolean>]
|
||||
|
||||
|
@ -816,6 +816,19 @@ function restoreWritable(name) {
|
||||
delete process[name].writeTimes;
|
||||
}
|
||||
|
||||
exports.runWithInvalidFD = function(func) {
|
||||
let fd = 1 << 30;
|
||||
// Get first known bad file descriptor. 1 << 30 is usually unlikely to
|
||||
// be an valid one.
|
||||
try {
|
||||
while (fs.fstatSync(fd--) && fd > 0);
|
||||
} catch (e) {
|
||||
return func(fd);
|
||||
}
|
||||
|
||||
exports.printSkipMessage('Could not generate an invalid fd');
|
||||
};
|
||||
|
||||
exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
|
||||
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
|
||||
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
|
||||
|
Loading…
x
Reference in New Issue
Block a user