Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7160,7 +7160,6 @@ def create_alg(self, typ, name):

# bpo-31705: On kernel older than 4.5, sendto() failed with ENOKEY,
# at least on ppc64le architecture
@unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented
@support.requires_linux_version(4, 5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Retain expected failures on the unfixed Android target

On Android builds where AF_ALG socket creation is permitted, _have_socket_alg() enables this class, but AF_ALG address parsing remains gated to target_os = "linux" in crates/stdlib/src/socket.rs:1765–1766. Consequently, create_alg() still fails at bind() with OSError: bind(): bad family, and removing these decorators converts expected failures into test errors without fixing Android's implementation. Preserve conditional expected failures for that target; AGENTS.md permits removing these annotations only when the tests actually pass.

AGENTS.md reference: AGENTS.md:L280-L281

Useful? React with 👍 / 👎.

def test_sha256(self):
expected = bytes.fromhex("ba7816bf8f01cfea414140de5dae2223b00361a396"
Expand All @@ -7179,7 +7178,6 @@ def test_sha256(self):
op.send(b'')
self.assertEqual(op.recv(512), expected)

@unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented
def test_hmac_sha1(self):
# gh-109396: In FIPS mode, Linux 6.5 requires a key
# of at least 112 bits. Use a key of 152 bits.
Expand All @@ -7195,7 +7193,6 @@ def test_hmac_sha1(self):

# Although it should work with 3.19 and newer the test blocks on
# Ubuntu 15.10 with Kernel 4.2.0-19.
@unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented
@support.requires_linux_version(4, 3)
def test_aes_cbc(self):
key = bytes.fromhex('06a9214036b8a15b512e03d534120006')
Expand Down Expand Up @@ -7237,7 +7234,6 @@ def test_aes_cbc(self):
self.assertEqual(len(dec), msglen * multiplier)
self.assertEqual(dec, msg * multiplier)

@unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented
@support.requires_linux_version(4, 9) # see gh-73510
def test_aead_aes_gcm(self):
kernel_version = support._get_kernel_version("Linux")
Expand Down Expand Up @@ -7307,7 +7303,6 @@ def test_aead_aes_gcm(self):
res = op.recv(len(msg) - taglen)
self.assertEqual(plain, res[assoclen:])

@unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented
@support.requires_linux_version(4, 3) # see test_aes_cbc
def test_drbg_pr_sha256(self):
# deterministic random bit generator, prediction resistance, sha256
Expand Down
26 changes: 26 additions & 0 deletions crates/stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,32 @@ mod _socket {
zelf: &Py<Self>,
vm: &VirtualMachine,
) -> Result<(RawSocket, PyObjectRef), IoOrPyException> {
#[cfg(target_os = "linux")]
if zelf.family.load(Ordering::Relaxed) == c::AF_ALG {
// AF_ALG rejects accept when a peer address is requested.
let sock = zelf.sock_op(vm, SockWaitKind::Read, || {
let listener = zelf.sock_snapshot()?;
// SAFETY: The listener is a socket descriptor. Null pointers
// request no peer address, and a successful call returns a
// new descriptor owned by the caller.
let fd = unsafe {
c::accept4(
sock_fileno(&listener),
core::ptr::null_mut(),
core::ptr::null_mut(),
c::SOCK_CLOEXEC,
)
};
if fd < 0 {
Err(io::Error::last_os_error())
} else {
// SAFETY: accept4 returned a new, valid descriptor.
Ok(unsafe { sock_from_raw_unchecked(fd) })
}
})?;
return Ok((into_sock_fileno(sock), vm.ctx.none()));
}

// Use accept_raw() instead of accept() to avoid socket2's set_common_flags()
// which tries to set SO_NOSIGPIPE and fails with EINVAL on Unix domain sockets on macOS
let (sock, addr) = zelf.sock_op(vm, SockWaitKind::Read, || {
Expand Down
Loading