Skip to content

Commit bbff134

Browse files
author
andrew.kuchling
committed
[Bug #1222790] Set reuse-address and close-on-exec flags on the HTTP listening socket
git-svn-id: http://svn.python.org/projects/python/trunk@41585 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent f8d317f commit bbff134

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lib/SimpleXMLRPCServer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def export_add(self, x, y):
104104
import SocketServer
105105
import BaseHTTPServer
106106
import sys
107-
import os
107+
import os, fcntl
108108

109109
def resolve_dotted_attribute(obj, attr, allow_dotted_names=True):
110110
"""resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
@@ -465,13 +465,23 @@ class SimpleXMLRPCServer(SocketServer.TCPServer,
465465
from SimpleXMLRPCDispatcher to change this behavior.
466466
"""
467467

468+
allow_reuse_address = True
469+
468470
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
469471
logRequests=1):
470472
self.logRequests = logRequests
471473

472474
SimpleXMLRPCDispatcher.__init__(self)
473475
SocketServer.TCPServer.__init__(self, addr, requestHandler)
474476

477+
# [Bug #1222790] If possible, set close-on-exec flag; if a
478+
# method spawns a subprocess, the subprocess shouldn't have
479+
# the listening socket open.
480+
if hasattr(fcntl, 'FD_CLOEXEC'):
481+
flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
482+
flags |= fcntl.FD_CLOEXEC
483+
fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags)
484+
475485
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
476486
"""Simple handler for XML-RPC data passed through CGI."""
477487

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ Library
448448
disables recursive traversal through instance attributes, which can
449449
be exploited in various ways.
450450

451+
- Bug #1222790: in SimpleXMLRPCServer, set the reuse-address and close-on-exec
452+
flags on the HTTP listening socket.
453+
451454
- Bug #1110478: Revert os.environ.update to do putenv again.
452455

453456
- Bug #1103844: fix distutils.install.dump_dirs() with negated options.

0 commit comments

Comments
 (0)