Commit ddb055941b1 for nodejs

commit ddb055941b1901755ef33c208118815b3c586acb
Author: Trivikram Kamat <trivikr.dev@gmail.com>
Date:   Fri Oct 30 10:11:38 2026 -0700

    ffi: reject arguments after callback in registerCallback

    Passing the signature after the callback silently created a `void ()`
    callback, so native callers got no arguments forwarded and an
    undefined return value.

    Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
    Assisted-by: claude:opus-5.5
    PR-URL: https://github.com/nodejs/node/pull/66997
    Fixes: https://github.com/nodejs/node/issues/66996
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Anna Henningsen <anna@addaleax.net>

diff --git a/src/node_ffi.cc b/src/node_ffi.cc
index d6c50757f4f..410a5f867e3 100644
--- a/src/node_ffi.cc
+++ b/src/node_ffi.cc
@@ -1083,6 +1083,10 @@ void DynamicLibrary::RegisterCallback(const FunctionCallbackInfo<Value>& args) {
   }

   if (args[0]->IsFunction()) {
+    if (args.Length() > 1) {
+      THROW_ERR_INVALID_ARG_TYPE(env, "Callback must be the last argument");
+      return;
+    }
     fn = args[0].As<Function>();
   } else {
     if (!args[0]->IsObject() || args[0]->IsArray()) {
diff --git a/test/ffi/test-ffi-callbacks.js b/test/ffi/test-ffi-callbacks.js
index 2dca67d6605..70dc23d2cc2 100644
--- a/test/ffi/test-ffi-callbacks.js
+++ b/test/ffi/test-ffi-callbacks.js
@@ -63,6 +63,10 @@ test('ffi callback ref and unref APIs work', () => {
       return 0;
     },
   );
+  assert.throws(() => lib.registerCallback(() => {}, { arguments: ['i32'], return: 'i32' }), {
+    code: 'ERR_INVALID_ARG_TYPE',
+    message: 'Callback must be the last argument',
+  });

   try {
     lib.unrefCallback(voidCallback);