2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-03 15:55:46 +00:00

ProfileStorage: Store empty xattrs as empty string

... instead of None.

This avoids the need to allow type changes (None vs. str).

Also adjust the tests accordingly.
This commit is contained in:
Christian Boltz
2021-08-15 13:43:19 +02:00
parent bbe52a1eec
commit 337ebcd032
2 changed files with 8 additions and 8 deletions

View File

@@ -107,7 +107,7 @@ class ProfileStorage:
raise AppArmorBug('Attempt to change type of "%s" from %s to %s, value %s' % (key, type(self.data[key]), type(value), value)) raise AppArmorBug('Attempt to change type of "%s" from %s to %s, value %s' % (key, type(self.data[key]), type(value), value))
# allow writing str or None to some keys # allow writing str or None to some keys
elif key in ('xattrs', 'flags', 'filename'): elif key in ('flags', 'filename'):
if type_is_str(value) or value is None: if type_is_str(value) or value is None:
self.data[key] = value self.data[key] = value
else: else:
@@ -249,7 +249,7 @@ class ProfileStorage:
else: else:
prof_storage['profile_keyword'] = matches['profile_keyword'] prof_storage['profile_keyword'] = matches['profile_keyword']
prof_storage['attachment'] = matches['attachment'] or '' prof_storage['attachment'] = matches['attachment'] or ''
prof_storage['xattrs'] = matches['xattrs'] prof_storage['xattrs'] = matches['xattrs'] or ''
return (profile, hat, prof_storage) return (profile, hat, prof_storage)

View File

@@ -122,12 +122,12 @@ class TestSetInvalid(AATest):
class AaTest_parse_profile_start(AATest): class AaTest_parse_profile_start(AATest):
tests = [ tests = [
# profile start line profile hat profile hat attachment xattrs flags pps_set_hat_external # profile start line profile hat profile hat attachment xattrs flags pps_set_hat_external
(('/foo {', None, None), ('/foo', '/foo', None, None, None, False)), (('/foo {', None, None), ('/foo', '/foo', None, '', None, False)),
(('/foo (complain) {', None, None), ('/foo', '/foo', None, None, 'complain', False)), (('/foo (complain) {', None, None), ('/foo', '/foo', None, '', 'complain', False)),
(('profile foo /foo {', None, None), ('foo', 'foo', '/foo', None, None, False)), # named profile (('profile foo /foo {', None, None), ('foo', 'foo', '/foo', '', None, False)), # named profile
(('profile /foo {', '/bar', None), ('/bar', '/foo', None, None, None, False)), # child profile (('profile /foo {', '/bar', None), ('/bar', '/foo', None, '', None, False)), # child profile
(('/foo//bar {', None, None), ('/foo', 'bar', None, None, None, True )), # external hat (('/foo//bar {', None, None), ('/foo', 'bar', None, '', None, True )), # external hat
(('profile "/foo" (complain) {', None, None), ('/foo', '/foo', None, None, 'complain', False)), (('profile "/foo" (complain) {', None, None), ('/foo', '/foo', None, '', 'complain', False)),
(('profile "/foo" xattrs=(user.bar=bar) {', None, None), ('/foo', '/foo', None, 'user.bar=bar', None, False)), (('profile "/foo" xattrs=(user.bar=bar) {', None, None), ('/foo', '/foo', None, 'user.bar=bar', None, False)),
(('profile "/foo" xattrs=(user.bar=bar user.foo=*) {', None, None), ('/foo', '/foo', None, 'user.bar=bar user.foo=*', None, False)), (('profile "/foo" xattrs=(user.bar=bar user.foo=*) {', None, None), ('/foo', '/foo', None, 'user.bar=bar user.foo=*', None, False)),
(('/usr/bin/xattrs-test xattrs=(myvalue="foo.bar") {', None, None), ('/usr/bin/xattrs-test', '/usr/bin/xattrs-test', None, 'myvalue="foo.bar"', None, False)), (('/usr/bin/xattrs-test xattrs=(myvalue="foo.bar") {', None, None), ('/usr/bin/xattrs-test', '/usr/bin/xattrs-test', None, 'myvalue="foo.bar"', None, False)),