Skip to content

Commit 618bed6

Browse files
ffi: validate 'void' as parameter type in getFunction and getFunctions
Fixes: #63461 Signed-off-by: Anshikakalpana <anshikajain196872@gmail.com>
1 parent 1b04f16 commit 618bed6

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/ffi/types.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
202202
if (!ToFFIType(env, arg_str.ToStringView()).To(&arg_type)) {
203203
return {};
204204
}
205+
if (arg_type == &ffi_type_void) {
206+
THROW_ERR_INVALID_ARG_VALUE(
207+
env,
208+
"Argument %u of function %s must not be 'void'; "
209+
"use an empty array for no-argument functions",
210+
i,
211+
name);
212+
return {};
213+
}
205214

206215
args.push_back(arg_type);
207216
arg_type_names.emplace_back(arg_str.ToString());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!process.config.variables.node_use_ffi) {
6+
common.skip('requires FFI support');
7+
}
8+
9+
const assert = require('node:assert');
10+
const { spawnSync } = require('node:child_process');
11+
12+
// Regression test for https://github.com/nodejs/node/issues/63461
13+
// 'void' as a parameter type should throw ERR_INVALID_ARG_VALUE
14+
// instead of triggering ERR_INTERNAL_ASSERTION.
15+
16+
{
17+
const { stderr, status } = spawnSync(process.execPath, [
18+
'--expose-internals',
19+
'-e',
20+
`
21+
const { internalBinding } = require('internal/test/binding');
22+
const { DynamicLibrary } = internalBinding('ffi');
23+
const lib = new DynamicLibrary(null);
24+
lib.getFunction('f', { parameters: ['void'] });
25+
`,
26+
], {
27+
encoding: 'utf8',
28+
});
29+
30+
assert.strictEqual(status, 1);
31+
assert.match(stderr, /ERR_INVALID_ARG_VALUE/);
32+
assert.doesNotMatch(stderr, /ERR_INTERNAL_ASSERTION/);
33+
}

0 commit comments

Comments
 (0)