Skip to content

Fix sendmsg() implementation #24187

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adamscott
Copy link
Contributor

@adamscott adamscott commented Apr 25, 2025

One-char fix!
Finally, a little more complicated.

This PR introduces a new test. This test calls getifaddrs(), which internally would ultimately call setmsg().

The problem was there: calling getifaddrs() makes dest here undefined, but sock.type === {{{ cDefs.SOCK_DGRAM }}} would be true.

        if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
          // if we're not connected, open a new connection
          if (sock.type === {{{ cDefs.SOCK_DGRAM }}}) {
            if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
              dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
            }

The current behaviour would skip then the assignement and dest would be called just after, but throw as dest would be undefined.

My solution is to make sure to set dest even if the sock.type matches. Just to be sure, after the condition, I force the sock type. Therefore, I think the intent of #22630 is respected.

        if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
          // if we're not connected, open a new connection
          if (!dest || sock.type === {{{ cDefs.SOCK_DGRAM }}}) {
            sock.type === {{{ cDefs.SOCK_DGRAM }}};
            if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
              dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
            }

Fixes #23046.

@adamscott adamscott force-pushed the one-char-fix branch 2 times, most recently from 7b3c85c to 7cf5386 Compare April 25, 2025 19:20
@adamscott adamscott changed the title Fix issue where dest would be called while undef Fix sendmsg() implementation Apr 25, 2025
@adamscott
Copy link
Contributor Author

@sbc100 I completely rewrote my PR from the ground up. I added a test, changed the fix, and I updated the PR description.

@adamscott adamscott requested a review from sbc100 April 25, 2025 19:29
@adamscott
Copy link
Contributor Author

@sbc100 ci/circleci seems to break because emcc: error: LLVM version for clang executable "/root/emsdk/upstream/bin/clang" appears incorrect (seeing "21.0", expected "20") [-Wversion-check] [-Werror]

@adamscott adamscott force-pushed the one-char-fix branch 2 times, most recently from 76f8e4d to 5d47a1b Compare April 27, 2025 18:06
@sbc100
Copy link
Collaborator

sbc100 commented May 19, 2025

In the PR description I assume you meant to write sendmsg and not setmsg?

@sbc100
Copy link
Collaborator

sbc100 commented May 19, 2025

I wonder if the problem can instead be fixed at a higher level. It seems that getifaddrs in musl is using __rtnetlink_enumerate which uses PF_NETLINK protocol family.. which emscripten does not support.

Do i'm pretty sure getifaddrs does not work at all right? I don't how it fails? Presumably this crash is just the tip if the iceberg.

sbc100 added a commit to sbc100/emscripten that referenced this pull request May 19, 2025
We don't support AF_NETLINK sockets so just fail early here.

Replaces emscripten-core#24187
@sbc100 sbc100 mentioned this pull request May 19, 2025
@sbc100
Copy link
Collaborator

sbc100 commented May 19, 2025

I think I found a better solution which is simply not allow the AF_NETLINK socket to be created: #24364

sbc100 added a commit to sbc100/emscripten that referenced this pull request May 19, 2025
We don't support AF_NETLINK sockets so just fail early here.

Replaces emscripten-core#24187
sbc100 added a commit that referenced this pull request May 19, 2025
We don't support `AF_NETLINK` sockets so just fail early here.

Replaces #24187
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.

library_sockfs.js can access properties of undefined dest (logic flaw)
2 participants