Skip to content

Commit 89db5c3

Browse files
trivikraduh95
authored andcommitted
ffi: define function pointer property as own data property
`CreateFunction` assigned `pointer` with `Object::Set`, which walks `Function.prototype`. A non-writable inherited `pointer` turned the store into a silent no-op, so the function reported the inherited value instead of its native address. Use `CreateDataProperty`. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5.5 PR-URL: #67170 Fixes: #67169 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 3f12612 commit 89db5c3

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎src/node_ffi.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ MaybeLocal<Function> DynamicLibrary::CreateFunction(
364364
}
365365
ret->SetName(name_str.As<String>());
366366

367-
if (!ret->Set(
367+
if (!ret->CreateDataProperty(
368368
context,
369369
env->pointer_string(),
370370
BigInt::NewFromUnsigned(

‎test/ffi/test-ffi-dynamic-library.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,16 @@ test('DynamicLibrary exposes functions and symbols', () => {
9292
const lib = new ffi.DynamicLibrary(libraryPath);
9393

9494
try {
95+
// An inherited non-writable `pointer` must not shadow the address.
96+
Object.defineProperty(Function.prototype, 'pointer', {
97+
value: 1, writable: false, configurable: true,
98+
});
9599
const addI32 = lib.getFunction('add_i32', fixtureSymbols.add_i32);
96100
const addU64 = lib.getFunction('add_u64', {
97101
return: 'u64',
98102
arguments: ['u64', 'u64'],
99103
});
104+
delete Function.prototype.pointer;
100105
const addI32Ptr = lib.getSymbol('add_i32');
101106

102107
assert.strictEqual(addI32(20, 22), 42);

0 commit comments

Comments
 (0)