Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/templ.rs: fix handling of C string slices #612

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

niemeyer
Copy link
Contributor

@niemeyer niemeyer commented Sep 2, 2024

CommandLineParser is currently misbehaving due to improper data in its input argv parameter. The problem is caused by a blind cast of argv entries from &str into a C-like string, which does not offer the null termination guarantees. To fix that, create an actual CString and hold it while the pointer is in use.

It's worth noting that the mutable version of the macro still relies on undefined behavior, but this time of CString which does not guarantee correctness if its data is written into.

CommandLineParser is currently misbehaving due to improper data in
its input argv parameter. The problem is caused by a blind cast of
argv entries from &str into a C-like string, which does not offer the
null termination guarantees. To fix that, create an actual CString
and hold it while the pointer is in use.

It's worth noting that the mutable version of the macro still relies
on undefined behavior, but this time of CString which does not
guarantee correctness if its data is written into.
@twistedfall
Copy link
Owner

Thanks a lot, that's a very good catch!

@twistedfall twistedfall merged commit d728e9f into twistedfall:master Sep 2, 2024
15 checks passed
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.

2 participants