Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens Rust↔C FFI string handling by ensuring interior NUL (\0) bytes can’t cause CString::new() to panic, centralizing the behavior in a shared helper and updating call sites to use it.
Changes:
- Added
safe_cstring()helper in thefficrate to strip interior NUL bytes onCString::new()failure. - Updated
string_to_c()(and preflight error-string construction) to usesafe_cstring()instead ofCString::new(...).unwrap(). - Removed a duplicated local
string_to_c()helper from the preflight crate.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/stellar-rpc/lib/preflight/src/lib.rs | Switches preflight error-string construction to safe_cstring() and removes the local string_to_c() helper. |
| cmd/stellar-rpc/lib/ffi/src/lib.rs | Introduces safe_cstring() and routes string_to_c() through it to avoid panics on interior NUL bytes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| fn default() -> Self { | ||
| Self { | ||
| error: CString::new(String::new()).unwrap().into_raw(), | ||
| error: safe_cstring(String::new()).into_raw(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Handle
NulErrorfromCString::newand strip\0bytes.Why
While our usage is safe because the strings come from the WASM host VM which never includes user-controlled messages and only uses printable ASCII characters, it's always better to code defensively.
Known limitations
n/a