Skip to content

Commit 3b70e7a

Browse files
RafaelGSSdanielleadams
authored andcommitted
test: include strace openat test
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: #46150 Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 7e08ca1 commit 3b70e7a

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

.github/workflows/test-asan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
CXX: clang++
4646
LINK: clang++
4747
CONFIG_FLAGS: --enable-asan
48+
ASAN: true
4849
steps:
4950
- uses: actions/checkout@v3
5051
with:

test/common/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const isFreeBSD = process.platform === 'freebsd';
120120
const isOpenBSD = process.platform === 'openbsd';
121121
const isLinux = process.platform === 'linux';
122122
const isOSX = process.platform === 'darwin';
123+
const isAsan = process.env.ASAN !== undefined;
123124
const isPi = (() => {
124125
try {
125126
// Normal Raspberry Pi detection is to find the `Raspberry Pi` string in
@@ -898,6 +899,7 @@ const common = {
898899
invalidArgTypeHelper,
899900
isAIX,
900901
isAlive,
902+
isAsan,
901903
isDumbTerminal,
902904
isFreeBSD,
903905
isLinux,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { spawn, spawnSync } = require('node:child_process');
5+
const { createInterface } = require('node:readline');
6+
const assert = require('node:assert');
7+
8+
if (!common.hasCrypto)
9+
common.skip('missing crypto');
10+
if (!common.isLinux)
11+
common.skip('linux only');
12+
if (common.isAsan)
13+
common.skip('strace does not work well with address sanitizer builds');
14+
if (spawnSync('strace').error !== undefined) {
15+
common.skip('missing strace');
16+
}
17+
18+
{
19+
const allowedOpenCalls = new Set([
20+
'/etc/ssl/openssl.cnf',
21+
]);
22+
const strace = spawn('strace', [
23+
'-f', '-ff',
24+
'-e', 'trace=open,openat',
25+
'-s', '512',
26+
'-D', process.execPath, '-e', 'require("crypto")',
27+
]);
28+
29+
// stderr is the default for strace
30+
const rl = createInterface({ input: strace.stderr });
31+
rl.on('line', (line) => {
32+
if (!line.startsWith('open')) {
33+
return;
34+
}
35+
36+
const file = line.match(/"(.*?)"/)[1];
37+
// skip .so reading attempt
38+
if (file.match(/.+\.so(\.?)/) !== null) {
39+
return;
40+
}
41+
// skip /proc/*
42+
if (file.match(/\/proc\/.+/) !== null) {
43+
return;
44+
}
45+
46+
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`);
47+
});
48+
const debugOutput = [];
49+
strace.stderr.setEncoding('utf8');
50+
strace.stderr.on('data', (chunk) => {
51+
debugOutput.push(chunk.toString());
52+
});
53+
strace.on('error', common.mustNotCall());
54+
strace.on('exit', common.mustCall((code) => {
55+
assert.strictEqual(code, 0, debugOutput);
56+
const missingKeys = Array.from(allowedOpenCalls.keys());
57+
if (missingKeys.length) {
58+
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`);
59+
}
60+
}));
61+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy