Skip to content

fix: reject NULL string arguments in interface methods - #395

Open
Wenzel wants to merge 2 commits into
intel:mainfrom
Wenzel:fix/cstr-null-123
Open

Wenzel wants to merge 2 commits into
intel:mainfrom
Wenzel:fix/cstr-null-123

Conversation

@Wenzel

@Wenzel Wenzel commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #123

Summary

add_architecture_hint, repro and solution passed the caller's char * straight to CStr::from_ptr. A NULL pointer (e.g. Python None) is UB and segfaults Simics. Since ? only covers the UTF-8 check, which runs after the read, it doesn't catch this.

 add_architecture_hint / repro / solution
-  unsafe { CStr::from_ptr(ptr) }.to_str()?
+  unsafe { c_str_arg(ptr, "name") }?   // util: ensure!(!ptr.is_null()) then from_ptr

A NULL now returns an error like any other invalid argument. The generated ffi(expect) wrapper then reports it as Failed to execute FFI method solution: message must not be NULL. Non-NUL-terminated or dangling pointers can't be detected from Rust, so that stays the caller's contract. c_str_arg is an unsafe fn with a # Safety section.

Evidence

New test tests/null_string_args_latest.rs loads tsffs and calls tsffs.iface.fuzz.solution(1, None).

  • Before: Segmentation fault (SIGSEGV) in main thread ("simics") from libc at test.py line 5. Test FAILED.
  • After: Simics aborts with the must not be NULL panic message. Test ok. cargo clippy --all-targets is clean.

Merge Danger

Door: two-way

Blast Radius: small

Only NULL inputs behave differently. They used to crash Simics with a segfault; now they abort through the existing interface-error panic path with a clear message.

add_architecture_hint, repro and solution passed caller pointers straight
to CStr::from_ptr, so a NULL (e.g. Python None) segfaulted Simics.
Check for NULL first and return an error instead.
@Wenzel
Wenzel requested a balanced review from Copilot October 23, 2026 12:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Prevents UB/segfaults when Simics interface methods receive NULL string pointers by rejecting NULL before calling CStr::from_ptr, and adds a regression test for the reported crash.

Changes:

  • Added util::c_str_arg helper to reject NULL and convert C string args safely (w.r.t. NULL).
  • Updated interface methods (add_architecture_hint, repro, solution) to use c_str_arg instead of CStr::from_ptr directly.
  • Added regression test ensuring None/NULL string args fail with a clear error rather than segfaulting.
File Description
tests/​null_string_args_latest.rs Adds regression coverage for NULL string interface argument handling.
src/​util/​mod.rs Introduces c_str_arg helper to reject NULL prior to C string conversion.
src/​interfaces/​fuzz.rs Switches string pointer handling in repro/solution to the new helper.
src/​interfaces/​config.rs Switches add_architecture_hint to the new helper.

Review effort: Lite

Comment thread src/util/mod.rs Outdated
Comment thread src/util/mod.rs Outdated

This branch has not been deployed

No deployments
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.

Unsound Use of CStr::from_ptr in add_architecture_hint

2 participants