Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

windows: fix opening of read-only stdin pipes #1223

Closed
wants to merge 1 commit into from
Closed

windows: fix opening of read-only stdin pipes #1223

wants to merge 1 commit into from

Conversation

orangemocha
Copy link

Fix nodejs/node-v0.x-archive#7345

Google Chrome is launching native messaging hosts by invoking cmd.exe
with input/output redirected from/to named pipes. The host ends up
with a read-only handle to the stdin pipe. This is causing
SetNamedPipeHandleState to fail.

@Nodejs-Jenkins
Copy link

Thank you for contributing this pull request! Here are a few pointers to make sure your submission will be considered for inclusion.

The following commiters were not found in the CLA:

  • Alexis Campailla

You can fix all these things without opening another issue.

Please see CONTRIBUTING.md for more information

/* that is not a pipe. */
if (GetLastError() == ERROR_INVALID_PARAMETER) {
SetLastError(WSAENOTSOCK);
DWORD err = GetLastError();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define it at the top of the function.

@orangemocha
Copy link
Author

Updated, thanks.

@saghul
Copy link
Contributor

saghul commented Apr 1, 2014

Would uv_is_writable return false, or do we need to reset the writable flag? Also, any chance this could have a test?

Code looks ok to me, my Windows kung-fu is pretty limited though :-/

@orangemocha
Copy link
Author

Updated to reset writable flag. Added a test to node.js here: nodejs/node-v0.x-archive#7433

return UV_EINVAL;
}

uv_pipe_connection_init(pipe);
pipe->handle = os_handle;
pipe->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are the flags and handle set in the pipe now? I can't see it in the diff.

Copy link
Author

Choose a reason for hiding this comment

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

See line 1771:

  • DWORD duplex_flags = UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;

uv_set_pipe_handle is setting the flags, clearing UV_HANDLE_WRITABLE should the pipe be read-only.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but where do we save those flags into pipe->flags now?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see now, sorry.

@saghul
Copy link
Contributor

saghul commented Apr 9, 2014

LGTM, though I'd like @piscisaureus's blessing :-)

SetLastError(WSAENOTSOCK);
err = GetLastError();
if (err == ERROR_ACCESS_DENIED) {
/* SetNamedPipeHandleState can fail if the handle doesn't have either */
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it is lame, but could you please make it a single block comment?

@indutny
Copy link
Contributor

indutny commented Apr 9, 2014

LGTM

Fix nodejs/node-v0.x-archive#7345

Google Chrome is launching native messaging hosts by invoking cmd.exe
with input/output redirected from/to named pipes. The host ends up
with a read-only handle to the stdin pipe. This is causing
SetNamedPipeHandleState to fail.
@orangemocha
Copy link
Author

addressed style issues

@saghul
Copy link
Contributor

saghul commented Apr 10, 2014

Fixed a couple of style nits since I was there and landed it as ba47e68

Thanks @orangemocha!

@saghul saghul closed this Apr 10, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants