Skip to content

examples: fix local socket address lengths#3601

Open
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/local-socket-addrlen
Open

examples: fix local socket address lengths#3601
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/local-socket-addrlen

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep the existing compile-time sizeof(CONFIG_EXAMPLES_*_ADDR) path size, which already includes the terminating NUL.
  • Pass that bounded path size plus sizeof(sa_family_t) to bind(), connect(), and sendto() without adding a second NUL byte.
  • Remove the redundant manual terminator writes from the stream examples; strlcpy() already terminates the bounded destination.

Why

The examples treated sizeof(CONFIG_EXAMPLES_*_ADDR) as the pathname size, including its NUL terminator, and then added another byte to the socket address length. At the maximum pathname size, the supplied length could exceed struct sockaddr_un by one byte.

The stream examples also wrote sun_path[addrlen] = '\0' after clamping addrlen to UNIX_PATH_MAX, which could write one byte past sun_path.

Testing

  • Checked short, exact-capacity, and overlong configured paths: the bounded copy remains NUL-terminated and the resulting address length does not exceed sizeof(struct sockaddr_un).
  • git diff origin/master...HEAD --check
  • Confirmed all four rebased source blobs and the stable patch-id exactly match the previous implementation.
  • Rebased current head 4ed4f10e directly onto master 62b7e955.

CI notes

  • The previous Linux (sim-02) failure was in unrelated sim/login: CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD is not set.
  • Current master contains 1d15c81f (ci: supply sim/login ROMFS passwd credential in build jobs), which directly fixes that base CI configuration.
  • Linux (sim-02) and all other runnable matrix jobs pass on current head 4ed4f10e; macOS was skipped by workflow selection.

Comment thread examples/udgram/udgram_client.c Outdated
@Old-Ding Old-Ding force-pushed the codex/local-socket-addrlen branch from 36c57ec to bf8cc5c Compare July 8, 2026 03:35
@Old-Ding Old-Ding force-pushed the codex/local-socket-addrlen branch from bf8cc5c to 50ac971 Compare July 8, 2026 13:50
Comment thread examples/udgram/udgram_client.c Outdated
Comment thread examples/udgram/udgram_server.c Outdated
Comment thread examples/ustream/ustream_server.c Outdated
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

@Old-Ding please rebase your chang to the last master which fix the ci error.

@Old-Ding Old-Ding force-pushed the codex/local-socket-addrlen branch from 50ac971 to b016d61 Compare July 11, 2026 04:56
@github-actions github-actions Bot added Size: XS and removed Size: S labels Jul 11, 2026
The configured path size already includes its NUL terminator. Adding
another byte made the maximum address length exceed sockaddr_un, while
ustream could write at sun_path[UNIX_PATH_MAX].

Use the existing bounded copy length directly as the path portion of
the socket address and rely on strlcpy for termination.

Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
@Old-Ding Old-Ding force-pushed the codex/local-socket-addrlen branch from b016d61 to 4ed4f10 Compare July 12, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants