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

[stdlib] Fix input() segfaults on EOF #3919

Open
wants to merge 2 commits into
base: nightly
Choose a base branch
from

Conversation

mahiro21h
Copy link

@mahiro21h mahiro21h commented Dec 29, 2024

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.

related issue: #3908
closes: #3908

@mahiro21h mahiro21h requested a review from a team as a code owner December 29, 2024 11:56
@mahiro21h mahiro21h force-pushed the fix-input-segfaults-on-eof branch from 52df8e1 to df55a1f Compare December 29, 2024 12:36
@mahiro21h mahiro21h changed the title Fix input segfaults on eof [stdlib] Fix input segfaults on EOF Dec 29, 2024
@mahiro21h mahiro21h changed the title [stdlib] Fix input segfaults on EOF [stdlib] Fix input() segfaults on EOF Dec 29, 2024
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.

1 participant