[apparmor] [patch] Dear Santa
Christian Boltz
apparmor at cboltz.de
Sat Dec 26 20:41:15 UTC 2015
Dear Santa,
I know I'm late, but -
Can you please add the python developer(s) responsible for
http://bugs.python.org/issue10076 to your black book?
Having to add a workaround for a 5 years old bug, which even has a
patch attached to the bugreport, is not nice :-/
[patch] Implement __deepcopy__() for aare
Thanks to http://bugs.python.org/issue10076, we need to implement this
ourself :-/
Also add some tests to ensure __deepcopy__() works as expected.
I found this bug while testing the next patch series, which crashed
aa-cleanprof with
TypeError: cannot deepcopy this pattern object
[ 50-aare-deepcopy.diff ]
--- utils/apparmor/aare.py 2015-12-26 21:37:04.534751923 +0100
+++ utils/apparmor/aare.py 2015-12-26 21:34:48.575725530 +0100
@@ -46,6 +46,13 @@
'''returns a "printable" representation of AARE'''
return "AARE('%s')" % self.regex
+ def __deepcopy__(self, memo):
+ # thanks to http://bugs.python.org/issue10076, we need to implement this ourself
+ if self.orig_regex:
+ return AARE(self.orig_regex, is_path=False, log_event=True)
+ else:
+ return AARE(self.regex, is_path=False)
+
def match(self, expression):
'''check if the given expression (string or AARE) matches the regex'''
--- utils/test/test-aare.py 2015-12-26 21:37:04.534751923 +0100
+++ utils/test/test-aare.py 2015-12-26 21:37:14.302681989 +0100
@@ -13,6 +13,7 @@
import unittest
from common_test import AATest, setup_all_loops
+from copy import deepcopy
import re
from apparmor.common import convert_regexp, AppArmorBug, AppArmorException
from apparmor.aare import AARE, convert_expression_to_aare
@@ -223,6 +224,25 @@
obj = AARE('/foo', True)
self.assertEqual(str(obj), "AARE('/foo')")
+class TestAAREDeepcopy(AATest):
+ tests = [
+ # regex is path? log event expected (dummy value)
+ (AARE('/foo', False) , True),
+ (AARE('/foo', False, True) , True),
+ (AARE('/foo', True) , True),
+ (AARE('/foo', True, True) , True),
+ ]
+
+ def _run_test(self, params, expected):
+ dup = deepcopy(params)
+
+ self.assertTrue(params.match('/foo'))
+ self.assertTrue(dup.match('/foo'))
+
+ self.assertEqual(params.regex, dup.regex)
+ self.assertEqual(params.orig_regex, dup.orig_regex)
+ self.assertEqual(params.orig_regex, dup.orig_regex)
+
setup_all_loops(__name__)
if __name__ == '__main__':
Regards,
Christian Boltz
--
Wir waren vor einiger Zeit schonmal "soweit fertig". Dann kam
Gerald, fand 1000 Sachen Scheisse, hat 500 Sachen nicht begriffen
und 250 falsch gemacht. :-)))))) [Ratti in fontlinge-devel]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20151226/0e7af6c8/attachment.pgp>
More information about the AppArmor
mailing list