Skip to content

fix(network): bound gethostname copy to guest namelen - #40

Merged
midwan merged 1 commit into
masterfrom
fix/host-gethostname-overflow
Sep 15, 2026
Merged

midwan merged 1 commit into
masterfrom
fix/host-gethostname-overflow

Conversation

@midwan

@midwan midwan commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #39 (found by Codex post-merge): host_gethostname() passed the guest-supplied namelen to trap_put_string(), whose direct-memory path copies through the terminating NUL and ignores maxlen. A hostname longer than the caller's buffer wrote past the trap_valid_address(name, namelen) range into adjacent guest memory.

Fix: truncate the hostname to namelen - 1 characters, NUL-terminate, and copy with trap_put_bytes(), which is strictly bounded by its byte count. namelen == 0 now fails fast.

Noted while auditing other trap_put_string() callsites: cfgfile.cpp:8240 and cfgfile.cpp:8282 have the same guest-length + host-string pattern (WinUAE-lineage code, predates #39) — proposing as a separate follow-up.

Verification

  • Clean build (macOS, Apple Silicon)
  • AROS boot with socket_emu=true: no errors, clean exit

trap_put_string() writes through the terminating NUL and ignores its
maxlen on the direct-memory path, so a hostname longer than the
caller's buffer spilled past the validated namelen range into
adjacent guest memory. Truncate to namelen-1 plus NUL and copy with
the strictly bounded trap_put_bytes().
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-15T18:57:55.144751Z c417ccb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@midwan
midwan merged commit 47a9f2b into master Sep 15, 2026
10 checks passed
@midwan
midwan deleted the fix/host-gethostname-overflow branch September 15, 2026 18:58
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.

1 participant