-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[stdlib] Fix input()
segfaults on EOF
#3919
Conversation
Signed-off-by: Raysan Alawami <[email protected]>
Signed-off-by: Raysan Alawami <[email protected]>
52df8e1
to
df55a1f
Compare
input()
segfaults on EOF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Signed-off-by: Joe Loser <[email protected]>
!sync |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
Landed in 4ef6859! Thank you for your contribution 🎉 |
[External] [stdlib] Fix `input()` segfaults on EOF pressing `ctrl-d` with no input when `input()` is called causes mojo to crash because `read_until_delimiter()` doesn't check the return value of the C function `getdelim()`. it assumes `getdelim()` always succeeds and so, in the case of an error, it blindly creates a `StringRef` with its length set to the return value - 1 (so the length is -2 in this case). this `StringRef` is then passed to `String()` which in turn passes the `StringRef` to `memcpy()` with a count of -2 and ultimately crashing mojo. this pr adds a check in `read_until_delimiter()` to check if `getdelim()` failed and raise an error if it does, along with a test to ensure `read_until_delimiter()` continues to behave as it should. Fixes #3908 Co-authored-by: mahiro21h <[email protected]> Closes #3919 MODULAR_ORIG_COMMIT_REV_ID: c3457f3377bfcfe0379e31fbd31e72ec53fe7516
[External] [stdlib] Fix `input()` segfaults on EOF pressing `ctrl-d` with no input when `input()` is called causes mojo to crash because `read_until_delimiter()` doesn't check the return value of the C function `getdelim()`. it assumes `getdelim()` always succeeds and so, in the case of an error, it blindly creates a `StringRef` with its length set to the return value - 1 (so the length is -2 in this case). this `StringRef` is then passed to `String()` which in turn passes the `StringRef` to `memcpy()` with a count of -2 and ultimately crashing mojo. this pr adds a check in `read_until_delimiter()` to check if `getdelim()` failed and raise an error if it does, along with a test to ensure `read_until_delimiter()` continues to behave as it should. Fixes modularml#3908 Co-authored-by: mahiro21h <[email protected]> Closes modularml#3919 MODULAR_ORIG_COMMIT_REV_ID: c3457f3377bfcfe0379e31fbd31e72ec53fe7516 Signed-off-by: Joshua James Venter <[email protected]>
pressing
ctrl-d
with no input wheninput()
is called causes mojo to crash becauseread_until_delimiter()
doesn't check the return value of the C functiongetdelim()
. it assumesgetdelim()
always succeeds and so, in the case of an error, it blindly creates aStringRef
with its length set to the return value - 1 (so the length is -2 in this case). thisStringRef
is then passed toString()
which in turn passes theStringRef
tomemcpy()
with a count of -2 and ultimately crashing mojo.this pr adds a check in
read_until_delimiter()
to check ifgetdelim()
failed and raise an error if it does, along with a test to ensureread_until_delimiter()
continues to behave as it should.related issue: #3908
closes: #3908