Skip to content

libc/netdb: Keep *ahost intact on failure and preserve errno in rexec_af. - #22963

Open
yashgoyal0110 wants to merge 1 commit into
apache:masterfrom
yashgoyal0110:libc/netdb-rexec-fixes
Open

yashgoyal0110 wants to merge 1 commit into
apache:masterfrom
yashgoyal0110:libc/netdb-rexec-fixes

Conversation

@yashgoyal0110

Copy link
Copy Markdown
Contributor

Summary

In libs/libc/netdb/lib_rexec.c, rexec_af() previously assigned *ahost = strdup(res->ai_canonname) before socket(), connect(), and the initial write() calls completed, and freed *ahost on the error path without restoring the caller's pointer.

Hold the duplicated canonical name in a local pointer and assign *ahost only after the connection and protocol writes succeed, check !*ahost on entry, format inport as unsigned uint16_t, and save errno around close(sock) on failure.

Fixes #22958

Impact

  • Impact on user: *ahost is no longer left pointing to freed memory when rexec() / rexec_af() fails, and errno reflects the failing socket operation.
  • Impact on build: None.
  • Impact on hardware: None.
  • Impact on documentation: None.
  • Impact on security: Avoids dangling *ahost pointer after failed connection attempts.
  • Impact on compatibility: None.

Testing

Tested rexec_af() failure paths (*ahost == NULL, socket() failure, connect() failure) and verified *ahost and errno are preserved.

…_af.

Validate *ahost != NULL in rexec_af(), store the duplicated canonical hostname into *ahost only after the connection and protocol writes succeed so *ahost is not left pointing to freed memory on error, and preserve errno across close() in the error path.

Fixes: apache#22958

Assisted-by: GPT-5.4
Signed-off-by: YASH GOYAL <yg364550@gmail.com>
@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: libc/netdb: rexec_af() leaves dangling *ahost on failure and clobbers errno on close()

2 participants