Replace copy.deepcopy of RequestContext with copy.copy

Instance of RequestContext contains many objects and some of them like
mutexes could not be copied. Also a deepcopy of the entire
RequestContext wastes CPU time.

To avoid problems with deepcopy and avoid performance overhead this
patch changes deepcopy of RequestContext to shallow copy and makes
deepcopy of only the 'roles' member because of security issue
LP #1386932.

Closes-Bug: #1506958
Related-Bug: #1386932
Change-Id: I1e2c00e95e1c4bcd0ec7bf075458789d6fb06e99
(cherry picked from commit 82457f2462)
This commit is contained in:
Marian Horban 2015-12-07 07:30:11 -05:00 committed by Matt Riedemann
parent 2da1d8ba76
commit 3c2d75d60a
1 changed files with 4 additions and 1 deletions

View File

@ -195,7 +195,10 @@ class RequestContext(context.RequestContext):
def elevated(self, read_deleted=None):
"""Return a version of this context with admin flag set."""
context = copy.deepcopy(self)
context = copy.copy(self)
# context.roles must be deepcopied to leave original roles
# without changes
context.roles = copy.deepcopy(self.roles)
context.is_admin = True
if 'admin' not in context.roles: