From 618bed640e024bb2139a5fb897188338864041da Mon Sep 17 00:00:00 2001 From: anshikakalpana Date: Sat, 23 May 2026 14:21:34 +0530 Subject: [PATCH] ffi: validate 'void' as parameter type in getFunction and getFunctions Fixes: https://github.com/nodejs/node/issues/63461 Signed-off-by: Anshikakalpana --- src/ffi/types.cc | 9 +++++++ test/parallel/test-ffi-void-parameter.js | 33 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/parallel/test-ffi-void-parameter.js diff --git a/src/ffi/types.cc b/src/ffi/types.cc index 4d5062cdf832fb..fe393a0bad646e 100644 --- a/src/ffi/types.cc +++ b/src/ffi/types.cc @@ -202,6 +202,15 @@ Maybe 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()); diff --git a/test/parallel/test-ffi-void-parameter.js b/test/parallel/test-ffi-void-parameter.js new file mode 100644 index 00000000000000..1756dd61a5a820 --- /dev/null +++ b/test/parallel/test-ffi-void-parameter.js @@ -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/); +}