Skip to content

Conversation

@cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Sep 18, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

src

Description of change

This commit prevents thrown JavaScript exceptions from crashing the process in node_contextify's CopyProperties() function.

Closes #8537

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Sep 18, 2016
@imyller
Copy link
Member

imyller commented Sep 18, 2016

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a TryCatch because...

Copy link
Member

@bnoordhuis bnoordhuis Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...the proper way is to check:

auto maybe_has = sandbox_obj->HasOwnProperty(context, key);
if (!maybe_has.IsJust()) break;  // Exception pending.
auto has = maybe_has.FromJust();
// ...

Copy link
Member

@bnoordhuis bnoordhuis Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to ReThrow() if you drop the TryCatch, the exception will simply bubble up.

(I believe the caller of CopyProperties() is doing that wrong, too.)

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 19, 2016

Thanks @bnoordhuis. Updated with your suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: I would be okay with just keeping the bool type explicit, using auto here doesn’t save any space and erases information that a reader of the code may find helpful.

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 19, 2016

@addaleax done.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@bnoordhuis
Copy link
Member

Tangential: CopyProperties() doesn't look very rigorous to me. GetOwnPropertyNames() returns only enumerable string properties; no symbols, no non-enumerable properties.

Perhaps only enumerable makes some sense because you don't want to copy over globals like Array and Date.

@fhinkel fhinkel added the vm Issues and PRs related to the vm subsystem. label Sep 20, 2016
@fhinkel
Copy link
Member

fhinkel commented Sep 20, 2016

FYI: We made API changes upstream in V8, so CopyProperties() will go away soon.

@fhinkel
Copy link
Member

fhinkel commented Sep 20, 2016

Can you add a regression test?

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 20, 2016

@fhinkel what do you mean? I thought I did (see the other changed file) :-)

@fhinkel
Copy link
Member

fhinkel commented Sep 20, 2016

So sorry, I must have completely missed that! LGTM.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@imyller imyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jasnell
Copy link
Member

jasnell commented Sep 20, 2016

This commit prevents thrown JavaScript exceptions from crashing
the process in node_contextify's CopyProperties() function.

Fixes: nodejs#8537
PR-URL: nodejs#8649
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@MylesBorins
Copy link
Contributor

@cjihrig I've set this as do not land as proxies are not on v4.x

Let me know if I'm mistaken here

@bnoordhuis
Copy link
Member

I think it would be good to back-port, it's not just proxies that can cause exceptions.

Fishrock123 pushed a commit that referenced this pull request Oct 11, 2016
This commit prevents thrown JavaScript exceptions from crashing
the process in node_contextify's CopyProperties() function.

Fixes: #8537
PR-URL: #8649
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ilkka Myller <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. vm Issues and PRs related to the vm subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants