Skip to content

Fix memory unsafety in Reader::push by simply removing it #21902

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/libstd/old_io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,26 +547,6 @@ pub trait Reader {
Ok(buf[0])
}

/// Reads up to `len` bytes and appends them to a vector.
/// Returns the number of bytes read. The number of bytes read may be
/// less than the number requested, even 0. Returns Err on EOF.
///
/// # Error
///
/// If an error occurs during this I/O operation, then it is returned
/// as `Err(IoError)`. See `read()` for more details.
fn push(&mut self, len: uint, buf: &mut Vec<u8>) -> IoResult<uint> {
let start_len = buf.len();
buf.reserve(len);

let n = {
let s = unsafe { slice_vec_capacity(buf, start_len, start_len + len) };
try!(self.read(s))
};
unsafe { buf.set_len(start_len + n) };
Ok(n)
}

/// Reads at least `min` bytes, but no more than `len`, and appends them to
/// a vector.
/// Returns the number of bytes read.
Expand Down