Thanks to visit codestin.com
Credit goes to github.com

Skip to content

socket: return EPROTONOSUPPORT on invalid protocol #16479

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

Merged
merged 2 commits into from
Mar 13, 2022

Conversation

tiran
Copy link
Contributor

@tiran tiran commented Mar 12, 2022

Invalid socket protocol now fails with errno EPROTONOSUPPORT instead of
crashing with an assertion error.

Invalid socket protocol now fails with errno EPROTONOSUPPORT instead of
crashing with an assertion error.
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Thanks!

if (protocol) {
assert(streaming == (protocol == {{{ cDefine('IPPROTO_TCP') }}})); // if SOCK_STREAM, must be tcp
if (streaming && protocol && protocol != {{{ cDefine('IPPROTO_TCP') }}}) {
throw new FS.ErrnoError({{{ cDefine('EPROTONOSUPPORT') }}}); // if SOCK_STREAM, must be tcp or 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it really ok to be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my experience it is very common to use socket(AF_INET, SOCK_STREAM, 0) to create a IPv4 TCP socket. I have rarely seen IPPROTO_TCP. It works fine on Linux, FreeBSD, macOS, and Windows.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yes. I see. From the man page:

Normally only  a  single  protocol exists to support a particular socket type within a given
protocol family, in which case protocol can be specified as 0.

@sbc100 sbc100 merged commit 3acd086 into emscripten-core:main Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants