Skip to content

Commit 178ae6b

Browse files
committed
src: only delete[] on Windows
1 parent 21951c6 commit 178ae6b

File tree

2 files changed

+85
-30
lines changed

2 files changed

+85
-30
lines changed

src/node_sea.cc

+2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ std::tuple<int, char**> FixupArgsForSEA(int argc, char** argv) {
271271
new_argv.emplace_back(argv[0]);
272272
new_argv.insert(new_argv.end(), argv, argv + argc);
273273
new_argv.emplace_back(nullptr);
274+
#ifdef _WIN32
274275
delete[] argv;
276+
#endif
275277
argc = new_argv.size() - 1;
276278
argv = new_argv.data();
277279
}

test/common/sea.js

+83-30
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ const tmpdir = require('../common/tmpdir');
66
const { inspect } = require('util');
77

88
const { readFileSync, copyFileSync, statSync } = require('fs');
9-
const {
10-
spawnSyncAndExitWithoutError,
11-
} = require('../common/child_process');
9+
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
1210

1311
function skipIfSingleExecutableIsNotSupported() {
1412
if (!process.config.variables.single_executable_application)
@@ -18,31 +16,48 @@ function skipIfSingleExecutableIsNotSupported() {
1816
common.skip(`Unsupported platform ${process.platform}.`);
1917

2018
if (process.platform === 'linux' && process.config.variables.is_debug === 1)
21-
common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');
19+
common.skip(
20+
'Running the resultant binary fails with `Couldn\'t read target executable"`.'
21+
);
2222

2323
if (process.config.variables.node_shared)
24-
common.skip('Running the resultant binary fails with ' +
25-
'`/home/iojs/node-tmp/.tmp.2366/sea: error while loading shared libraries: ' +
26-
'libnode.so.112: cannot open shared object file: No such file or directory`.');
24+
common.skip(
25+
'Running the resultant binary fails with ' +
26+
'`/home/iojs/node-tmp/.tmp.2366/sea: error while loading shared libraries: ' +
27+
'libnode.so.112: cannot open shared object file: No such file or directory`.'
28+
);
2729

2830
if (process.config.variables.icu_gyp_path === 'tools/icu/icu-system.gyp')
29-
common.skip('Running the resultant binary fails with ' +
30-
'`/home/iojs/node-tmp/.tmp.2379/sea: error while loading shared libraries: ' +
31-
'libicui18n.so.71: cannot open shared object file: No such file or directory`.');
32-
33-
if (!process.config.variables.node_use_openssl || process.config.variables.node_shared_openssl)
34-
common.skip('Running the resultant binary fails with `Node.js is not compiled with OpenSSL crypto support`.');
31+
common.skip(
32+
'Running the resultant binary fails with ' +
33+
'`/home/iojs/node-tmp/.tmp.2379/sea: error while loading shared libraries: ' +
34+
'libicui18n.so.71: cannot open shared object file: No such file or directory`.'
35+
);
36+
37+
if (
38+
!process.config.variables.node_use_openssl ||
39+
process.config.variables.node_shared_openssl
40+
)
41+
common.skip(
42+
'Running the resultant binary fails with `Node.js is not compiled with OpenSSL crypto support`.'
43+
);
3544

3645
if (process.config.variables.want_separate_host_toolset !== 0)
37-
common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.');
46+
common.skip(
47+
'Running the resultant binary fails with `Segmentation fault (core dumped)`.'
48+
);
3849

3950
if (process.platform === 'linux') {
40-
const osReleaseText = readFileSync('/etc/os-release', { encoding: 'utf-8' });
51+
const osReleaseText = readFileSync('/etc/os-release', {
52+
encoding: 'utf-8',
53+
});
4154
const isAlpine = /^NAME="Alpine Linux"/m.test(osReleaseText);
4255
if (isAlpine) common.skip('Alpine Linux is not supported.');
4356

4457
if (process.arch === 's390x') {
45-
common.skip('On s390x, postject fails with `memory access out of bounds`.');
58+
common.skip(
59+
'On s390x, postject fails with `memory access out of bounds`.'
60+
);
4661
}
4762
}
4863

@@ -54,7 +69,9 @@ function skipIfSingleExecutableIsNotSupported() {
5469
readFileSync(process.execPath);
5570
} catch (e) {
5671
if (e.code === 'ERR_FS_FILE_TOO_LARGE') {
57-
common.skip('The Node.js binary is too large to be supported by postject');
72+
common.skip(
73+
'The Node.js binary is too large to be supported by postject'
74+
);
5875
}
5976
}
6077

@@ -66,34 +83,54 @@ function skipIfSingleExecutableIsNotSupported() {
6683
const stat = statSync(process.execPath);
6784
const expectedSpace = stat.size + 10 * 1024 * 1024;
6885
if (!tmpdir.hasEnoughSpace(expectedSpace)) {
69-
common.skip(`Available disk space < ${Math.floor(expectedSpace / 1024 / 1024)} MB`);
86+
common.skip(
87+
`Available disk space < ${Math.floor(expectedSpace / 1024 / 1024)} MB`
88+
);
7089
}
7190
}
7291

73-
function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow = false) {
92+
function generateSEA(
93+
targetExecutable,
94+
sourceExecutable,
95+
seaBlob,
96+
verifyWorkflow = false
97+
) {
7498
try {
7599
copyFileSync(sourceExecutable, targetExecutable);
76100
} catch (e) {
77-
const message = `Cannot copy ${sourceExecutable} to ${targetExecutable}: ${inspect(e)}`;
101+
const message = `Cannot copy ${sourceExecutable} to ${targetExecutable}: ${inspect(
102+
e
103+
)}`;
78104
if (verifyWorkflow) {
79105
throw new Error(message);
80106
}
81107
common.skip(message);
82108
}
83109
console.log(`Copied ${sourceExecutable} to ${targetExecutable}`);
84110

85-
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
111+
const postjectFile = fixtures.path(
112+
'postject-copy',
113+
'node_modules',
114+
'postject',
115+
'dist',
116+
'cli.js'
117+
);
86118
try {
87119
spawnSyncAndExitWithoutError(process.execPath, [
88120
postjectFile,
89121
targetExecutable,
90122
'NODE_SEA_BLOB',
91123
seaBlob,
92-
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
93-
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
124+
'--sentinel-fuse',
125+
'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
126+
...(process.platform === 'darwin'
127+
? ['--macho-segment-name', 'NODE_SEA']
128+
: []),
94129
]);
95130
} catch (e) {
96-
const message = `Cannot inject ${seaBlob} into ${targetExecutable}: ${inspect(e)}`;
131+
const message = `Cannot inject ${seaBlob} into ${targetExecutable}: ${inspect(
132+
e
133+
)}`;
97134
if (verifyWorkflow) {
98135
throw new Error(message);
99136
}
@@ -103,8 +140,12 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
103140

104141
if (process.platform === 'darwin') {
105142
try {
106-
spawnSyncAndExitWithoutError('codesign', [ '--sign', '-', targetExecutable ]);
107-
spawnSyncAndExitWithoutError('codesign', [ '--verify', targetExecutable ]);
143+
spawnSyncAndExitWithoutError('codesign', [
144+
'--sign',
145+
'-',
146+
targetExecutable,
147+
]);
148+
spawnSyncAndExitWithoutError('codesign', ['--verify', targetExecutable]);
108149
} catch (e) {
109150
const message = `Cannot sign ${targetExecutable}: ${inspect(e)}`;
110151
if (verifyWorkflow) {
@@ -115,7 +156,7 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
115156
console.log(`Signed ${targetExecutable}`);
116157
} else if (process.platform === 'win32') {
117158
try {
118-
spawnSyncAndExitWithoutError('where', [ 'signtool' ]);
159+
spawnSyncAndExitWithoutError('where', ['signtool']);
119160
} catch (e) {
120161
const message = `Cannot find signtool: ${inspect(e)}`;
121162
if (verifyWorkflow) {
@@ -125,10 +166,22 @@ function generateSEA(targetExecutable, sourceExecutable, seaBlob, verifyWorkflow
125166
}
126167
let stderr;
127168
try {
128-
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]));
129-
spawnSyncAndExitWithoutError('signtool', ['verify', '/pa', 'SHA256', targetExecutable]);
169+
({ stderr } = spawnSyncAndExitWithoutError('signtool', [
170+
'sign',
171+
'/fd',
172+
'SHA256',
173+
'/a',
174+
targetExecutable,
175+
]));
176+
spawnSyncAndExitWithoutError('signtool', [
177+
'verify',
178+
'/pa',
179+
targetExecutable,
180+
]);
130181
} catch (e) {
131-
const message = `Cannot sign ${targetExecutable}: ${inspect(e)}\n${stderr}`;
182+
const message = `Cannot sign ${targetExecutable}: ${inspect(
183+
e
184+
)}\n${stderr}`;
132185
if (verifyWorkflow) {
133186
throw new Error(message);
134187
}

0 commit comments

Comments
 (0)