From: Douglas Bagnall Date: Fri, 26 Oct 2018 06:33:48 +0000 (+1300) Subject: python dbcheck: don't use mutable default args X-Git-Tag: tdb-1.3.17~977 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f17a77af4602af02ebb05b8f6d6344c2dadf62f0;p=thirdparty%2Fsamba.git python dbcheck: don't use mutable default args In this code def f(a, b=[]): b.append(a) return b all single argument calls to f() will affect the same copy of b. In the controls case, controls=None has the same effect as controls=[]. Signed-off-by: Douglas Bagnall Reviewed-by: Noel Power --- diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index 9af11162ce5..030bea4b299 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -226,7 +226,8 @@ class dbcheck(object): raise pass - def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']): + def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=None, + attrs=None): '''perform a database check, returning the number of errors found''' res = self.samdb.search(base=DN, scope=scope, attrs=['dn'], controls=controls) self.report('Checking %u objects' % len(res)) @@ -2021,14 +2022,15 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) raise KeyError - def check_object(self, dn, attrs=['*']): + def check_object(self, dn, attrs=None): '''check one object''' if self.verbose: self.report("Checking object %s" % dn) - - # If we modify the pass-by-reference attrs variable, then we get a - # replPropertyMetadata for every object that we check. - attrs = list(attrs) + if attrs is None: + attrs = ['*'] + else: + # make a local copy to modify + attrs = list(attrs) if "dn" in map(str.lower, attrs): attrs.append("name") if "distinguishedname" in map(str.lower, attrs):