Skip to content

apps/wolfssh: fix ssh://hostname destination without explicit port#1006

Open
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5575
Open

apps/wolfssh: fix ssh://hostname destination without explicit port#1006
yosuke-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f_5575

Conversation

@yosuke-wolfssl
Copy link
Copy Markdown
Contributor

Description

config_parse_command_line documents ssh://[user@]hostname[:port], but the URI branch only assigned config->hostname when an explicit :port was present. A normal wolfssh ssh://example.com (or ssh://user@example.com) left config->hostname == NULL, so wolfSSH_Client aborted with "client requires a hostname parameter" instead of connecting on the default port 22.

Addressed by f_5575.

Changes

  • Extracted the destination-parsing logic out of the static, untestable inline block in wolfssh.c into a new WOLFSSH_LOCAL ClientParseDestination() in apps/wolfssh/common.c (declared in common.h). config_parse_command_line now calls it, so the parsing logic exists in exactly one place.
  • The URI branch now always assigns the hostname when host text is present, defaulting the port to 22 when none is given.
    A malformed destination with no host text (ssh://, ssh://user@) leaves hostname NULL so the existing downstream check rejects it cleanly.
  • The helper uses a commit-at-end pattern: it parses into local buffers and only frees-old/assigns the caller's user/hostname/port once parsing fully succeeds. On any failure the caller's values are left untouched (no partial output, no leak), and user/hostname are freed symmetrically before replacement. All WMALLOCs are NULL-checked; returns WS_SUCCESS / WS_BAD_ARGUMENT / WS_MEMORY_E.
  • Softened the leading-@ diagnostic to a non-error note ("note: empty user name before '@'") so the message matches the outcome (empty user is accepted, as before).
  • Added new tests to exercise new code path.

@yosuke-wolfssl yosuke-wolfssl self-assigned this Jun 8, 2026
Copilot AI review requested due to automatic review settings June 8, 2026 08:23
Copy link
Copy Markdown
Contributor

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

This PR fixes wolfssh destination parsing so ssh://hostname (and ssh://user@hostname) correctly sets config->hostname even when no explicit port is provided, aligning behavior with the documented command-line syntax and avoiding the downstream “client requires a hostname parameter” abort.

Changes:

  • Refactors destination parsing into a new ClientParseDestination() helper in apps/wolfssh/common.c and reuses it from apps/wolfssh/wolfssh.c.
  • Ensures the URI form assigns hostname when host text exists and preserves the caller’s default port when no :port is present.
  • Adds regression tests covering URI and non-URI destination parsing variants, including malformed inputs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/regress.c Adds regression coverage for destination parsing (issue 5575) and related edge cases.
apps/wolfssh/wolfssh.c Replaces inline destination parsing with a call to ClientParseDestination().
apps/wolfssh/common.h Declares the new ClientParseDestination() helper.
apps/wolfssh/common.c Implements ClientParseDestination() with commit-at-end semantics and memory handling.

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

Comment thread apps/wolfssh/common.c Outdated
Comment thread apps/wolfssh/common.c
Comment thread tests/regress.c Outdated
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #1006

Scan targets checked: none
Failed targets: wolfssh-bugs, wolfssh-src

⚠️ Review incomplete — one or more scan targets failed before findings could be produced. See the Fenrir PR review detail page for logs.

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.

3 participants