summaryrefslogtreecommitdiffstats
path: root/Demo/pysvr
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-19 21:29:28 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-19 21:29:28 (GMT)
commit42ded89c088a2b101731c5106b08299341cf7deb (patch)
tree97c3d17f157ad84bfde61babaf336c3286f62787 /Demo/pysvr
parenteca991df27393c4ed4ea7b164b31aa631a2478ef (diff)
downloadcpython-42ded89c088a2b101731c5106b08299341cf7deb.zip
cpython-42ded89c088a2b101731c5106b08299341cf7deb.tar.gz
cpython-42ded89c088a2b101731c5106b08299341cf7deb.tar.bz2
Reformulate security check using getsockname().
Diffstat (limited to 'Demo/pysvr')
-rwxr-xr-xDemo/pysvr/pysvr.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Demo/pysvr/pysvr.py b/Demo/pysvr/pysvr.py
index 329909b..a62fc5c 100755
--- a/Demo/pysvr/pysvr.py
+++ b/Demo/pysvr/pysvr.py
@@ -48,14 +48,15 @@ def main_thread(port):
print "Listening on port", port, "..."
while 1:
(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))
del conn, addr
def service_thread(conn, 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()),
caddr),
stdin = conn.makefile("r")