-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { spawn, spawnSync } = require('node:child_process'); | ||
const { createInterface } = require('node:readline'); | ||
const assert = require('node:assert'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
if (!common.isLinux) | ||
common.skip('linux only'); | ||
if (spawnSync('strace').error !== undefined) { | ||
common.skip('missing strace'); | ||
} | ||
|
||
{ | ||
const allowedOpenCalls = new Set([ | ||
'/etc/ssl/openssl.cnf', | ||
]); | ||
const strace = spawn('strace', [ | ||
'-f', '-ff', | ||
'-e', 'trace=openat', | ||
'-s', '128', | ||
'-D', process.execPath, '-e', 'require("crypto")', | ||
]); | ||
|
||
// stderr is the default for strace | ||
const rl = createInterface({ input: strace.stderr }); | ||
rl.on('line', (line) => { | ||
if (!line.startsWith('openat')) { | ||
return; | ||
} | ||
|
||
const file = line.match(/"(.*?)"/)[1]; | ||
// skip .so reading attempt | ||
if (file.match(/.+\.so(\.?)/) !== null) { | ||
return; | ||
} | ||
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`); | ||
}); | ||
|
||
strace.on('error', common.mustNotCall()); | ||
strace.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0); | ||
const missingKeys = Array.from(allowedOpenCalls.keys()); | ||
if (missingKeys.length) { | ||
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`); | ||
} | ||
})); | ||
} |