-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-strace-openat-openssl.js
More file actions
68 lines (62 loc) · 1.94 KB
/
test-strace-openat-openssl.js
File metadata and controls
68 lines (62 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'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 (common.isASan)
common.skip('strace does not work well with address sanitizer builds');
if (process.config.variables.node_shared_openssl) {
common.skip('external shared openssl may open other files');
}
if (spawnSync('strace').error !== undefined) {
common.skip('missing strace');
}
{
const allowedOpenCalls = new Set([
'/etc/ssl/openssl.cnf',
]);
const syscalls = ['openat'];
if (process.arch !== 'riscv64' && process.arch !== 'riscv32') {
syscalls.push('open');
}
const strace = spawn('strace', [
'-f', '-ff',
'-e', `trace=${syscalls.join(',')}`,
'-s', '512',
'-D', process.execPath, '-e', 'require("crypto")',
]);
// stderr is the default for strace
const rl = createInterface({ input: strace.stderr });
rl.on('line', common.mustCallAtLeast((line) => {
if (!line.startsWith('open')) {
return;
}
const file = line.match(/"(.*?)"/)[1];
// skip .so reading attempt
if (file.match(/.+\.so(\.?)/) !== null) {
return;
}
// skip /proc/*
if (file.match(/\/proc\/.+/) !== null) {
return;
}
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`);
}));
const debugOutput = [];
strace.stderr.setEncoding('utf8');
strace.stderr.on('data', (chunk) => {
debugOutput.push(chunk.toString());
});
strace.on('error', common.mustNotCall());
strace.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, debugOutput);
const missingKeys = Array.from(allowedOpenCalls.keys());
if (missingKeys.length) {
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`);
}
}));
}