Skip to content

Commit 60ee04a

Browse files
authored
Update socketpair w/ CVE-2024-3219 fix (#2468)
1 parent de43eee commit 60ee04a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

kafka/vendor/socketpair.py

+17
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
5353
raise
5454
finally:
5555
lsock.close()
56+
57+
# Authenticating avoids using a connection from something else
58+
# able to connect to {host}:{port} instead of us.
59+
# We expect only AF_INET and AF_INET6 families.
60+
try:
61+
if (
62+
ssock.getsockname() != csock.getpeername()
63+
or csock.getsockname() != ssock.getpeername()
64+
):
65+
raise ConnectionError("Unexpected peer connection")
66+
except:
67+
# getsockname() and getpeername() can fail
68+
# if either socket isn't connected.
69+
ssock.close()
70+
csock.close()
71+
raise
72+
5673
return (ssock, csock)
5774

5875
socket.socketpair = socketpair

0 commit comments

Comments
 (0)