-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Fix String.f32 and String.f64 errors with non null terminated strings #4132
Conversation
Is there any way to test this? I can't think of anything but I wanted to bring it up as a topic. |
Marking as do not merge for now since the implementation in this PR has a bug related to reallocation. Will fix it soon-ish. @SeanTAllen It requires some thinking. It is possible, but it requires control over how memory is allocated in order to produce a valid buffer overflow from the C side. |
I've added a test and dropped the "We haven't seen errors from this so far, but let's err on the side of caution" from the commit message. Here's a small program that shows the problem with not passing null-terminated strings to C: actor Main
new create(env: Env) =>
(let str1, let str2: String ref) = "1.1".clone().chop(1)
try
// Comment the line below to make str1.f32 fail,
// which means that str1.f32 is looking at the memory from str2
str2(0)? = 0
env.out.print(str1.f32()?.string()) // should print "1"
else
env.err.print("str1.f32() failed")
end |
This needs release notes |
Hi @ergl, The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do. Release notes are added by creating a uniquely named file in the The basic format of the release notes (using markdown) should be:
Thanks. |
These methods rely on strof/strod, which require null-terminated strings. We were passing our pointer to C without first checking if our string was null-terminated, which means that C would be able to read past our memory allocation. This fixes #1445
These methods rely on strof/strod, which require null-terminated strings. We
were passing our pointer to C without first checking if our string was
null-terminated, which means that C would be able to read past our memory
allocation.
This fixes #1445