-
Notifications
You must be signed in to change notification settings - Fork 137
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 UB when interacting with Stream::Null(_) #2802
base: master
Are you sure you want to change the base?
Conversation
…tr_as_cell! These two functions are pretty unsafe, but having these assertions makes it easier to catch UB in testing.
Heads up: Remember to |
I would expect a null stream to act like reading/writing to |
f2a4ef8
to
c31e369
Compare
c31e369
to
7108e87
Compare
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.
I think that adding a test for at_end_of_steam/1
is also a good idea.
ErrorKind::PermissionDenied, | ||
StreamError::ReadFromOutputStream, | ||
)), | ||
Stream::Null(_) => Ok(buf.len()), |
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.
This is not only an unexpected behavior for a null stream (at least if we are mimicking /dev/null
behavior), but I think also plain wrong. When read, /dev/null
is EOF, and that means that 0 bytes should be read (see docs). Here it means we should return Ok(0)
.
Returning Ok(buf.len())
means that the caller will think the buffer was filled (even though it wasn't) and use its data. buf
is not necessarily zeroed before this call, and so may have garbled data from a previous use.
The following test triggers UB on master, while using public-facing APIs:
This PR fixes #2801, by:
atom!("null_stream")
, which is mapped toStream::Null(Default::default())
inMachine::configure_streams()
.stream_as_cell!
macro into animpl From<Stream> for HeapCellValue
.I left in the sanity checks used while debugging the issue, in case someone inadvertently creates another null Cons in the future.