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

Fix is_null_terminated reading arbitrary memory (issue #1425) #1429

Merged
merged 8 commits into from
Nov 23, 2016
2 changes: 1 addition & 1 deletion packages/builtin/string.pony
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ actor Main
which may be present earlier in the content of the string.
If you need a null-terminated copy of this string, use the clone method.
"""
(_alloc > 0) and (_ptr._apply(_size) == 0)
(_alloc > 0) and (_alloc != _size) and (_ptr._apply(_size) == 0)

fun utf32(offset: ISize): (U32, U8) ? =>
"""
Expand Down
7 changes: 7 additions & 0 deletions packages/builtin_test/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ class iso _TestStringIsNullTerminated is UnitTest
h.assert_true("0123456".trim(2, 4).clone().is_null_terminated())
h.assert_false("0123456".trim(2, 4).is_null_terminated())

h.assert_true(String.from_iso_array(recover
['a', 'b', 'c']
end).is_null_terminated())
h.assert_false(String.from_iso_array(recover
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] // power of two sized array
end).is_null_terminated())


class iso _TestSpecialValuesF32 is UnitTest
"""
Expand Down