Commit 84524454 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-31247: xmlrpc.server: break reference cycle (#3166)

xmlrpc.server now explicitly breaks reference cycles when using
sys.exc_info() in code handling exceptions.
parent f432a323
...@@ -270,10 +270,14 @@ class SimpleXMLRPCDispatcher: ...@@ -270,10 +270,14 @@ class SimpleXMLRPCDispatcher:
except: except:
# report exception back to server # report exception back to server
exc_type, exc_value, exc_tb = sys.exc_info() exc_type, exc_value, exc_tb = sys.exc_info()
try:
response = dumps( response = dumps(
Fault(1, "%s:%s" % (exc_type, exc_value)), Fault(1, "%s:%s" % (exc_type, exc_value)),
encoding=self.encoding, allow_none=self.allow_none, encoding=self.encoding, allow_none=self.allow_none,
) )
finally:
# Break reference cycle
exc_type = exc_value = exc_tb = None
return response.encode(self.encoding, 'xmlcharrefreplace') return response.encode(self.encoding, 'xmlcharrefreplace')
...@@ -365,10 +369,14 @@ class SimpleXMLRPCDispatcher: ...@@ -365,10 +369,14 @@ class SimpleXMLRPCDispatcher:
) )
except: except:
exc_type, exc_value, exc_tb = sys.exc_info() exc_type, exc_value, exc_tb = sys.exc_info()
try:
results.append( results.append(
{'faultCode' : 1, {'faultCode' : 1,
'faultString' : "%s:%s" % (exc_type, exc_value)} 'faultString' : "%s:%s" % (exc_type, exc_value)}
) )
finally:
# Break reference cycle
exc_type = exc_value = exc_tb = None
return results return results
def _dispatch(self, method, params): def _dispatch(self, method, params):
...@@ -630,10 +638,14 @@ class MultiPathXMLRPCServer(SimpleXMLRPCServer): ...@@ -630,10 +638,14 @@ class MultiPathXMLRPCServer(SimpleXMLRPCServer):
# (each dispatcher should have handled their own # (each dispatcher should have handled their own
# exceptions) # exceptions)
exc_type, exc_value = sys.exc_info()[:2] exc_type, exc_value = sys.exc_info()[:2]
try:
response = dumps( response = dumps(
Fault(1, "%s:%s" % (exc_type, exc_value)), Fault(1, "%s:%s" % (exc_type, exc_value)),
encoding=self.encoding, allow_none=self.allow_none) encoding=self.encoding, allow_none=self.allow_none)
response = response.encode(self.encoding, 'xmlcharrefreplace') response = response.encode(self.encoding, 'xmlcharrefreplace')
finally:
# Break reference cycle
exc_type = exc_value = None
return response return response
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
......
xmlrpc.server now explicitly breaks reference cycles when using
sys.exc_info() in code handling exceptions.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment