[apparmor] [patch] Dear Santa
John Johansen
john.johansen at canonical.com
Sat Dec 26 22:59:30 UTC 2015
On 12/26/2015 12:41 PM, Christian Boltz wrote:
> 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
>
>
That is really sad,
Acked-by: John Johansen <john.johansen at canonical.com>
>
> [ 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
>
>
>
More information about the AppArmor
mailing list