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

  • compute udgram and ustream Unix-domain pathname lengths with strnlen()
  • copy with space for the terminating NUL
  • pass sizeof(sa_family_t) + strlen(path) + 1 to bind(), connect(), and sendto()

Why

The examples used sizeof(CONFIG_EXAMPLES_*_ADDR) as the pathname length and then added another NUL byte to the sockaddr length. For maximum-length paths this can make the supplied address length one byte larger than struct sockaddr_un.

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

Testing

  • git diff --check HEAD~1..HEAD
  • git show --stat --check --format=fuller HEAD
  • Not run: local NuttX apps build, because this Windows workstation does not have gcc, clang, or cc installed.

CI notes

  • Current Linux (arm-08) log download returns BlobNotFound / HTTP 404, so the decisive CI log is no longer available.
  • gh pr checks --required currently reports no required checks for this branch.


server.sun_family = AF_LOCAL;
strlcpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen);
strlcpy(server.sun_path, CONFIG_EXAMPLES_UDGRAM_ADDR, addrlen + 1);

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.

why change? strlcpy could ensure '\0' is terminated at the end of server.sun_path

The udgram and ustream examples used sizeof(CONFIG_EXAMPLES_*_ADDR)
as the pathname length and then added another NUL byte to the sockaddr
length. That made the maximum address length one byte larger than
struct sockaddr_un, and ustream also wrote a terminator at
sun_path[UNIX_PATH_MAX].

Track the pathname length with strnlen(), copy with room for the
terminator, and pass sizeof(sa_family_t) + addrlen + 1 to the socket
calls.

Signed-off-by: Old-Ding <ai.neo.ae86@gmail.com>
@Old-Ding Old-Ding force-pushed the codex/local-socket-addrlen branch from bf8cc5c to 50ac971 Compare July 8, 2026 13:50
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.

3 participants