-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: print External address from inspect #34398
Conversation
src/node_util.cc
Outdated
static void GetExternalValue( | ||
const FunctionCallbackInfo<Value>& args) { | ||
CHECK(args[0]->IsExternal()); | ||
auto isolate = args.GetIsolate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice! Thank you!
This is not a blocker at all, but I'd prefer specify the type
auto isolate = args.GetIsolate(); | |
Isolate* isolate = args.GetIsolate(); |
Just a sugestion, not a blocker.
I think this always prints the pointer, unlike what @addaleax suggested in #28250 (comment). Anna expressed potential security concerns there. |
@tniessen Yeah, it’s … not simple. On the one hand, the pointer should not end up in the hands of an attacker – on the other hand, if you’re publicly sharing debugging information for internal objects, like |
I am not overly concerned either. Are there any objects returned by core APIs that contain externals that would expose internal pointers when |
@tniessen No, Node.js core should currently be fine anyway. We only use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM then, thank you for the explanation @addaleax.
src/node_util.cc
Outdated
|
||
void* ptr = external->Value(); | ||
char val[20]; | ||
snprintf(val, sizeof(val), "%p", ptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%p
can either format the pointer as 1234abcde
or 0x1234abcd
, and there's also potential inconsistency around NULL pointers. I'd cast the pointer to uint64_t
and format it with PRIx64
from <cinttypes>
.
An alternative solution is to turn the pointer into a BigInt
with v8::BigInt::NewFromUnsigned()
and do the formatting in JS land with value.toString(16)
.
test/parallel/test-util-inspect.js
Outdated
assert.strictEqual(util.inspect((new JSStream())._externalStream), | ||
'[External]'); | ||
assert.match(util.inspect((new JSStream())._externalStream), | ||
/^\[External: .*?\]$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the value is a non-empty hex string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/^\[External: .*?\]$/); | |
/^\[External: [0-9a-f]+\]$/); |
@juanarbol @bnoordhuis @tniessen Updated, PTAL. |
Changes still LGTM, but the branch seems to have unrelated changes. Maybe a merge commit is the problem? |
0387c8d
to
880c5b1
Compare
Landed in fe2a7f0 |
Fixes: #28250 PR-URL: #34398 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
This does not land cleanly on v14.x, should it be backported? |
Fixes: nodejs#28250 PR-URL: nodejs#34398 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Fixes: #28250 PR-URL: #34398 Backport-PR-URL: #34583 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Fixes: #28250 PR-URL: #34398 Backport-PR-URL: #34583 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Fixes: #28250 PR-URL: #34398 Backport-PR-URL: #34583 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Fixes: #28250
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes