Skip to content

RxD Fix#874

Open
ejohnstown wants to merge 3 commits intowolfSSL:masterfrom
ejohnstown:rxd-fix
Open

RxD Fix#874
ejohnstown wants to merge 3 commits intowolfSSL:masterfrom
ejohnstown:rxd-fix

Conversation

@ejohnstown
Copy link
Contributor

@ejohnstown ejohnstown commented Feb 2, 2026

  1. Forwarding fixes in echoserver. (Really a general channel issue.)
  2. Agent fixes in echoserver.
  3. Added a test for forwarding.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes handling around “channel RX’d” (WS_CHAN_RXD) and agent setup paths, primarily to improve forwarding behavior in the echoserver and make agent-related code compile cleanly.

Changes:

  • Treat WS_CHAN_RXD as a successful outcome for returning lastRxId from wolfSSH_worker().
  • Silence unused-parameter warnings in agent stubs.
  • Fix echoserver agent UNIX-socket setup flow so it proceeds correctly after snprintf() and simplifies the socket() error assignment.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/ssh.c Returns channelId not only on WS_SUCCESS but also on WS_CHAN_RXD so callers can identify the channel that received data.
src/agent.c Adds WOLFSSH_UNUSED(agent) to avoid unused-parameter warnings when logging is compiled out.
examples/echoserver/echoserver.c Corrects agent local setup flow after snprintf() and adjusts UNIX-socket bind/setup logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

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

Changes look okay. I sent a message asking about expected output and return values from running the new scripts/fwd.test.

@JacobBarthelmeh
Copy link
Contributor

Assigning to John for investigating into the test case behavior.

1. When wolfSSH_worker() receives channel data, it should set the
   channelId for the data. It was not happening. Change the check for
   WS_SUCCESS to also check for WS_CHAN_RXD.
1. Fix a couple unused variable warnings.
2. In wolfSSH_AGENT_DefaultActions(), fix comparison to the result of
   snprintf() treating normal result as an error. Reset the return code
   for the error state of the socket() command. Remove the size variable
   and just use sizeof() the sockaddr_un. Better cleanup of agent
   startup failures.
1. Add a test script and expect script for testing forwarding.
2. Update portfwd to have a ready file option.
3. Fix echoserver error string, needed NL.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

examples/portfwd/portfwd.c:325

  • The new -R <readyFile> option is parsed, but ShowUsage() doesn’t mention it. This makes the CLI help inaccurate; please update the usage text to document -R and what it writes to the file.
    while ((ch = mygetopt(argc, argv, "?f:h:p:t:u:F:P:R:T:")) != -1) {
        switch (ch) {
            case 'h':
                host = myoptarg;
                break;

            case 'f':
                if (myoptarg == NULL)
                    err_sys("null argument found");
                fwdFromPort = (word16)atoi(myoptarg);
                break;

            case 'p':
                if (myoptarg == NULL)
                    err_sys("null argument found");
                port = (word16)atoi(myoptarg);
                #if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
                    if (port == 0)
                        err_sys("port number cannot be 0");
                #endif
                break;

            case 't':
                if (myoptarg == NULL)
                    err_sys("null argument found");
                fwdToPort = (word16)atoi(myoptarg);
                break;

            case 'u':
                username = myoptarg;
                break;

            case 'F':
                fwdFromHost = myoptarg;
                break;

            case 'P':
                password = myoptarg;
                break;

            case 'R':
                readyFile = myoptarg;
                break;

            case 'T':
                fwdToHost = myoptarg;
                break;

            case '?':
                ShowUsage();
                exit(EXIT_SUCCESS);

            default:
                ShowUsage();
                exit(MY_EX_USAGE);
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

endif

dist_noinst_SCRIPTS+= scripts/external.test
dist_noinst_SCRIPTS+= scripts/external.test scripts/fwd.test
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

scripts/fwd.test depends on scripts/fwd.test.expect, but include.am only adds scripts/fwd.test to dist_noinst_SCRIPTS. This will break make distcheck / running tests from a release tarball because the .expect file won’t be distributed. Add scripts/fwd.test.expect to the dist list (or another appropriate dist_* variable) alongside scripts/fwd.test.

Suggested change
dist_noinst_SCRIPTS+= scripts/external.test scripts/fwd.test
dist_noinst_SCRIPTS+= scripts/external.test scripts/fwd.test scripts/fwd.test.expect

Copilot uses AI. Check for mistakes.
Comment on lines +418 to +419
int l = WSNPRINTF(portStr, sizeof(portStr), "%d\n", (int)port);
WFWRITE(NULL, portStr, MIN((size_t)l, sizeof(portStr)), 1, f);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The ready-file writer is currently formatting/writing port (the SSH server port) rather than the local forwarded-from port that clients would need (likely fwdFromPort, which may be updated by tcp_listen() when binding ephemeral ports). Also, WSNPRINTF() can return a negative value on error; casting that to size_t can cause WFWRITE() to write an unintended length. Write the correct port value and guard against l <= 0 (and ideally handle a truncated result).

Suggested change
int l = WSNPRINTF(portStr, sizeof(portStr), "%d\n", (int)port);
WFWRITE(NULL, portStr, MIN((size_t)l, sizeof(portStr)), 1, f);
int l = WSNPRINTF(portStr, sizeof(portStr), "%d\n", (int)fwdFromPort);
if (l > 0) {
size_t writeLen = (size_t)l;
if (writeLen >= sizeof(portStr)) {
writeLen = sizeof(portStr) - 1;
}
WFWRITE(NULL, portStr, writeLen, 1, f);
}

Copilot uses AI. Check for mistakes.
Comment on lines +418 to +424
if (envSet) {
unsetenv(EnvNameAuthPort);
}
if (ctx->listenFd >= 0) {
close(ctx->listenFd);
ctx->listenFd = -1;
}
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

If bind() succeeds but setenv() or listen() fails, the setup error path closes the FD and unsets the env var, but it does not remove the already-created UNIX socket pathname. Add an unlink(ctx->name.sun_path) (or unlink(name->sun_path)) in the failure cleanup to avoid leaving stale /tmp/wolfserver.<pid> sockets behind.

Copilot uses AI. Check for mistakes.
Comment on lines 400 to 403
if (ret == 0) {
ret = bind(ctx->listenFd,
(struct sockaddr *)name, (socklen_t)size);
ret = bind(ctx->listenFd, (struct sockaddr *)name,
(socklen_t)sizeof(struct sockaddr_un));
}
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The bind() length was changed to sizeof(struct sockaddr_un), but elsewhere (e.g. the client-side agent code) the code computes strlen(path) + offsetof(sockaddr_un, sun_path). Using the full struct size can be less portable across UNIX variants; consider restoring the computed length here for consistency and compatibility.

Copilot uses AI. Check for mistakes.
#ifdef WOLFSSH_TEST_BLOCK
if (!nonBlock) {
ES_ERROR("Use -N when testing forced non blocking");
ES_ERROR("Use -N when testing forced non blocking\n");
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

Hyphenation in this user-facing message is inconsistent with the common term “non-blocking”. Update the wording to “forced non-blocking”.

Suggested change
ES_ERROR("Use -N when testing forced non blocking\n");
ES_ERROR("Use -N when testing forced non-blocking\n");

Copilot uses AI. Check for mistakes.
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.

4 participants