mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Reformulate security check using getsockname().
This commit is contained in:
parent
eca991df27
commit
42ded89c08
1 changed files with 4 additions and 3 deletions
|
@ -48,14 +48,15 @@ def main_thread(port):
|
||||||
print "Listening on port", port, "..."
|
print "Listening on port", port, "..."
|
||||||
while 1:
|
while 1:
|
||||||
(conn, addr) = sock.accept()
|
(conn, addr) = sock.accept()
|
||||||
|
if addr[0] != conn.getsockname()[0]:
|
||||||
|
conn.close()
|
||||||
|
print "Refusing connection from non-local host", addr[0], "."
|
||||||
|
continue
|
||||||
thread.start_new_thread(service_thread, (conn, addr))
|
thread.start_new_thread(service_thread, (conn, addr))
|
||||||
del conn, addr
|
del conn, addr
|
||||||
|
|
||||||
def service_thread(conn, addr):
|
def service_thread(conn, addr):
|
||||||
(caddr, cport) = addr
|
(caddr, cport) = addr
|
||||||
if caddr != socket.gethostbyname(socket.gethostname()):
|
|
||||||
print "Connection from", caddr, "not accepted."
|
|
||||||
return
|
|
||||||
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
|
print "Thread %s has connection from %s.\n" % (str(thread.get_ident()),
|
||||||
caddr),
|
caddr),
|
||||||
stdin = conn.makefile("r")
|
stdin = conn.makefile("r")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue