Skip to content

Commit 31c40f0

Browse files
ffi: validate 'void' as parameter type in getFunction and getFunctions
Fixes: #63461 Signed-off-by: Anshikakalpana <anshikajain196872@gmail.com> PR-URL: #63504 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 221ffc0 commit 31c40f0

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/ffi/types.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
164164
if (!ToFFIType(env, arg_str.ToStringView()).To(&arg_type)) {
165165
return {};
166166
}
167+
if (arg_type == &ffi_type_void) {
168+
THROW_ERR_INVALID_ARG_VALUE(
169+
env,
170+
"Argument %u of function %s must not be 'void'; "
171+
"use an empty array for no-argument functions",
172+
i,
173+
name);
174+
return {};
175+
}
167176

168177
args.push_back(arg_type);
169178
arg_type_names.emplace_back(arg_str.ToString());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Flags: --experimental-ffi
2+
'use strict';
3+
4+
const common = require('../common');
5+
common.skipIfFFIMissing();
6+
7+
const assert = require('node:assert');
8+
const ffi = require('node:ffi');
9+
const { libraryPath } = require('./ffi-test-common');
10+
11+
// Regression test for https://github.com/nodejs/node/issues/63461
12+
// 'void' as a parameter type should throw ERR_INVALID_ARG_VALUE
13+
// instead of triggering ERR_INTERNAL_ASSERTION.
14+
15+
const lib = new ffi.DynamicLibrary(libraryPath);
16+
17+
try {
18+
assert.throws(() => {
19+
lib.getFunction('add_i32', { return: 'i32', arguments: ['void'] });
20+
}, { code: 'ERR_INVALID_ARG_VALUE' });
21+
22+
assert.throws(() => {
23+
lib.getFunctions({
24+
add_i32: { return: 'i32', arguments: ['void'] },
25+
});
26+
}, { code: 'ERR_INVALID_ARG_VALUE' });
27+
} finally {
28+
lib.close();
29+
}

0 commit comments

Comments
 (0)