Skip to content

Commit 0896c0e

Browse files
committed
Avoid locked buffers in AF_ALG sends
Assisted-by: OpenAI Codex:model version not exposed
1 parent dbd0d15 commit 0896c0e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎crates/stdlib/src/socket.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,23 @@ mod _socket {
24242424
OptionalArg::Missing => None,
24252425
};
24262426

2427-
let buffers = msg.iter().map(|buf| buf.borrow_buf()).collect::<Vec<_>>();
2427+
if iv.as_ref().is_some_and(|iv| {
2428+
iv.len()
2429+
.checked_add(core::mem::size_of::<u32>())
2430+
.and_then(host_socket::checked_cmsg_space)
2431+
.is_none()
2432+
}) {
2433+
return Err(io::Error::new(
2434+
io::ErrorKind::InvalidInput,
2435+
"AF_ALG control data too large",
2436+
)
2437+
.into_pyexception(vm));
2438+
}
2439+
2440+
let buffers = msg
2441+
.iter()
2442+
.map(|buf| buf.borrow_buf_unlocked(vm))
2443+
.collect::<PyResult<Vec<_>>>()?;
24282444
let buffers = buffers
24292445
.iter()
24302446
.map(|buf| io::IoSlice::new(buf))

0 commit comments

Comments
 (0)