[apparmor] [patch] drop dead code from logparser.py parse_event_for_tree()

Seth Arnold seth.arnold at canonical.com
Mon Jun 26 19:20:47 UTC 2017


On Sun, Jun 25, 2017 at 11:08:47AM +0200, Christian Boltz wrote:
> Hello,
> 
> $subject.
> 
> In parse_event_for_tree(), map_log_type() never gets called. Also,
> aamode is never 'UNKNOWN'.
> 
> Proof for both: I have a local patch that raises an exception for both
> cases since two years ;-)
> 
> This patch drops the call to map_log_type() and the function itsself.
> It also adds a safety check for 'UNKNOWN' - instead of silently ignoring
> it, raise an exception (which will most probably never happen).
> 
> 
> 
> [ 02-logparser-dead-code.diff ]

Acked-by: Seth Arnold <seth.arnold at canonical.com>

Acked for trunk.

Thanks

> 
> --- utils/apparmor/logparser.py 2017-06-25 11:00:12.009972611 +0200
> +++ utils/apparmor/logparser.py 2017-06-25 11:00:02.678014174 +0200
> @@ -197,31 +197,13 @@
>              (pid, parent, mode, details) = e
>              self.add_to_tree(pid, parent, mode, details)
>  
> -    def map_log_type(self, log_type):
> -            if re.search('(UNKNOWN\[1501\]|APPARMOR_AUDIT|1501)', log_type):
> -                aamode = 'AUDIT'
> -            elif re.search('(UNKNOWN\[1502\]|APPARMOR_ALLOWED|1502)', log_type):
> -                aamode = 'PERMITTING'
> -            elif re.search('(UNKNOWN\[1503\]|APPARMOR_DENIED|1503)', log_type):
> -                aamode = 'REJECTING'
> -            elif re.search('(UNKNOWN\[1504\]|APPARMOR_HINT|1504)', log_type):
> -                aamode = 'HINT'
> -            elif re.search('(UNKNOWN\[1505\]|APPARMOR_STATUS|1505)', log_type):
> -                aamode = 'STATUS'
> -            elif re.search('(UNKNOWN\[1506\]|APPARMOR_ERROR|1506)', log_type):
> -                aamode = 'ERROR'
> -            else:
> -                aamode = 'UNKNOWN'
> -
> -            return aamode
> -
>      def parse_event_for_tree(self, e):
>          aamode = e.get('aamode', 'UNKNOWN')
>  
> -        if e.get('type', False):
> -            aamode = self.map_log_type(e['type'])
> +        if aamode == 'UNKNOWN':
> +            raise AppArmorBug('aamode is UNKNOWN - %s' % e['type'])  # should never happen
>  
> -        if aamode in ['UNKNOWN', 'AUDIT', 'STATUS', 'ERROR']:
> +        if aamode in ['AUDIT', 'STATUS', 'ERROR']:
>              return None
>  
>          if 'profile_set' in e['operation']:
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20170626/1970c701/attachment.pgp>


More information about the AppArmor mailing list