Skip to content
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

WIP: src: copy spawn_sync array as strings only #9824

Closed
wants to merge 1 commit into from

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Nov 28, 2016

Checklist
  • make -j8 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 changes the cloning mechanism in CopyJsStringArray(). Previously, the array would be cloned, including any problematic setters. This commit creates a new array and uses its setter.

This still needs tests if we decide to go this route, but fixes #9821

This commit changes the cloning mechanism in CopyJsStringArray().
Previously, the array would be cloned, including any problematic
setters. This commit creates a new array and uses its setter.
@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Nov 28, 2016
@mscdex mscdex added child_process Issues and PRs related to the child_process subsystem. wip Issues and PRs that are still a work in progress. labels Nov 28, 2016
@cjihrig
Copy link
Contributor Author

cjihrig commented Nov 28, 2016

Also seems to fix #9823. Could probably be pretty easily adapted to fix #9820 too, but does not currently.


// Convert all array elements to string. Modify the js object itself if
// needed - it's okay since we cloned the original object.
for (uint32_t i = 0; i < length; i++) {
if (!js_array->Get(i)->IsString())
js_array->Set(i, js_array->Get(i)->ToString(env()->isolate()));
auto item = input_array->Get(i)->ToString(env()->isolate());
Copy link
Member

Choose a reason for hiding this comment

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

may not be a bad idea to check the Get and ToString (ToLocalChecked is ugly but may be a good thing to have if you don't want to throw exceptions back to js)

@bnoordhuis
Copy link
Member

I have misgivings about fixing this on an ad hoc basis. If we feel that bad magic methods (toString, Symbol.toPrimitive, etc.) should be handled graciously, then we should come up with an overarching strategy and a set of rules to follow, and apply that consistently throughout the code base.

We've been inconsistent in the past with how we coerced numbers and it's been painful to change. Let's not repeat that mistake.

@cjihrig cjihrig closed this Nov 28, 2016
@tniessen
Copy link
Member

tniessen commented Jun 2, 2017

I think we agreed in #12372 to properly handle these kinds of errors in C++, even if it is ad hoc. Any reason not to reopen this? AFAIK this has not been fixed yet. I can take over if you want to @cjihrig.

@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 2, 2017

@tniessen I'm happy to reopen this, but you need to convince @bnoordhuis I think.

@tniessen
Copy link
Member

tniessen commented Jun 2, 2017

@bnoordhuis Any objections to fixing this ad hoc? I assumed your comment on that topic was pro making such changes.

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++. child_process Issues and PRs related to the child_process subsystem. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spawnSync's SyncProcessRunner::CopyJsStringArray segfaults with bad getter
6 participants