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

@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
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
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]

@@ -634,7 +634,8 @@ addToLibrary({
// connect, and lie, saying the data was sent now.
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 || sock.type === {{{ cDefs.SOCK_DGRAM }}}) {
sock.type = {{{ cDefs.SOCK_DGRAM }}};
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seem lik you could get here with !dest and with sock.type = {{{ cDefs.SOCK_STREAM }}}.. in which case this line would change the type of the socket, no?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but the check was specific for sock.type === {{{ cDefs.SOCK_DGRAM }}} only, that's why I forced it. Maybe it's ok to keep the socket type, then.

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