Rollup merge of #150986 - bishop-fix-read, r=ChrisDenton

std: Fix size returned by UEFI tcp4 read operations

The read and read_vectored methods were returning the length of the input buffer, rather than the number of bytes actually read. Fix by changing read_inner to return the correct value, and have both read and read_vectored return that.
This commit is contained in:
Matthias Krüger 2026-01-12 13:32:12 +01:00 committed by GitHub
commit db5ac01aba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -248,7 +248,7 @@ impl Tcp4 {
fragment_table: [fragment],
};
self.read_inner((&raw mut rx_data).cast(), timeout).map(|_| data_len as usize)
self.read_inner((&raw mut rx_data).cast(), timeout)
}
pub(crate) fn read_vectored(
@ -288,14 +288,14 @@ impl Tcp4 {
);
};
self.read_inner(rx_data.as_mut_ptr(), timeout).map(|_| data_length as usize)
self.read_inner(rx_data.as_mut_ptr(), timeout)
}
pub(crate) fn read_inner(
&self,
rx_data: *mut tcp4::ReceiveData,
timeout: Option<Duration>,
) -> io::Result<()> {
) -> io::Result<usize> {
let evt = unsafe { self.create_evt() }?;
let completion_token =
tcp4::CompletionToken { event: evt.as_ptr(), status: Status::SUCCESS };
@ -313,7 +313,8 @@ impl Tcp4 {
if completion_token.status.is_error() {
Err(io::Error::from_raw_os_error(completion_token.status.as_usize()))
} else {
Ok(())
let data_length = unsafe { (*rx_data).data_length };
Ok(data_length as usize)
}
}