Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ffi/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
if (!ToFFIType(env, arg_str.ToStringView()).To(&arg_type)) {
return {};
}
if (arg_type == &ffi_type_void) {
THROW_ERR_INVALID_ARG_VALUE(
env,
"Argument %u of function %s must not be 'void'; "
"use an empty array for no-argument functions",
i,
name);
return {};
}

args.push_back(arg_type);
arg_type_names.emplace_back(arg_str.ToString());
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-ffi-void-parameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const common = require('../common');

if (!process.config.variables.node_use_ffi) {
common.skip('requires FFI support');
}

const assert = require('node:assert');
const { spawnSync } = require('node:child_process');

// Regression test for https://github.com/nodejs/node/issues/63461
// 'void' as a parameter type should throw ERR_INVALID_ARG_VALUE
// instead of triggering ERR_INTERNAL_ASSERTION.

{
const { stderr, status } = spawnSync(process.execPath, [
'--expose-internals',
'-e',
`
const { internalBinding } = require('internal/test/binding');
const { DynamicLibrary } = internalBinding('ffi');
const lib = new DynamicLibrary(null);
lib.getFunction('f', { parameters: ['void'] });
`,
], {
encoding: 'utf8',
});

assert.strictEqual(status, 1);
assert.match(stderr, /ERR_INVALID_ARG_VALUE/);
assert.doesNotMatch(stderr, /ERR_INTERNAL_ASSERTION/);
}
Loading