Skip to content

Allocate channelName dynamically to shrink WOLFSSH struct by ~4KB#1104

Open
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:wolfssh-shrink-channelname
Open

Allocate channelName dynamically to shrink WOLFSSH struct by ~4KB#1104
aidangarske wants to merge 1 commit into
wolfSSL:masterfrom
aidangarske:wolfssh-shrink-channelname

Conversation

@aidangarske

Copy link
Copy Markdown
Member

Description

Converts the WOLFSSH.channelName field from a fixed 4096-byte inline array to a
dynamically-allocated buffer sized to the actual subsystem/exec name, cutting wolfSSH_new()'s per-connection allocation by 4096 bytes with no change to public
API behavior. It also short-circuits the allocation when the name is unchanged,
so the non-blocking SFTP/SCP handshake retry loops no longer churn malloc/free
on every poll.

Measured wolfSSH_new() allocation (−4096 B in every config):

  • 64-bit --enable-all: 11568 -> 7472 B
  • 64-bit minimal: 8400 -> 4304 B
  • 32-bit minimal: 7648 -> ~3556 B

Adds test_wolfSSH_SetChannelType covering the full branch set (NULL/zero/oversize
name, store+NUL-terminate, unchanged-name no-op, replace/free-previous, EXEC
fallthrough, unknown-type and server-side EXEC rejection).

Fixes concerns in: ZD 21984

Copilot AI review requested due to automatic review settings July 14, 2026 03:14
@aidangarske aidangarske self-assigned this Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces per-connection memory usage by changing WOLFSSH.channelName from a fixed-size inline buffer to a dynamically allocated buffer sized to the actual subsystem/exec name, and adds API tests to cover the updated channel-type/name behavior.

Changes:

  • Replace WOLFSSH.channelName[WOLFSSH_MAX_CHN_NAMESZ] with byte* channelName and allocate/free it dynamically.
  • Update wolfSSH_SetChannelType() to avoid realloc churn when the channel name is unchanged and to NUL-terminate stored names.
  • Add test_wolfSSH_SetChannelType to cover the new/updated branches and edge cases.

Reviewed changes

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

File Description
wolfssh/internal.h Shrinks WOLFSSH by making channelName a pointer instead of a 4KB inline array.
src/ssh.c Implements dynamic allocation + “unchanged name” fast-path in wolfSSH_SetChannelType().
src/internal.c Frees channelName in SshResourceFree() and adjusts debug logging in SendChannelRequest().
tests/api.c Adds a new API test to validate wolfSSH_SetChannelType() behavior across edge cases.

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

Comment thread src/ssh.c Outdated
Comment thread src/internal.c
Comment thread src/internal.c
Comment thread src/ssh.c Outdated
@aidangarske aidangarske force-pushed the wolfssh-shrink-channelname branch from 84498ed to c3e98a7 Compare July 14, 2026 16:13
@aidangarske aidangarske requested a review from ejohnstown July 14, 2026 16:15
@aidangarske aidangarske marked this pull request as ready for review July 14, 2026 16:15
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