# Buggy code
def _cmp_attrs(path, attrs):
    """
    .. versionadded:: 2018.3.0

    Compare attributes of a given file to given attributes.
    Returns a pair (list) where first item are attributes to
    add and second item are to be removed.

    Please take into account when using this function that some minions will
    not have lsattr installed.

    path
        path to file to compare attributes with.

    attrs
        string of attributes to compare against a given file
    """
    diff = [None, None]

    try:
        lattrs = lsattr(path).get(path, "")
    except AttributeError:
        # lsattr not installed
        return None

    old = [chr for chr in lattrs if chr not in attrs]
    if len(old) > 0:
        diff[1] = "".join(old)

    new = [chr for chr in attrs if chr not in lattrs]
    if len(new) > 0:
        diff[0] = "".join(new)

    return diff


# Traceback (IndexError)
[DEBUG   ] output: lsattr: 0514-500 Usage error - /var/spool/cron/crontabs/root

Usage:
lsattr {-D[-O]| -E[-O] -P[-O]| -F Format [-Z Character]} -l Name
[-a Attribute]...[-H] [-f File]
lsattr {-D[-O]| -F Format [-Z Character]}{[-c Class][-s Subclass][-t Type]}
[-a Attribute]... [-H][-f File]
lsattr -R {-l Name | [-c Class][-s Subclass][-t Type]} -a Attribute [-H]
[-f File]
lsattr {-l Name | [-c Class][-s Subclass][-t Type]} -o Operation [...]
-F Format [-Z Character][-f File][-H]
lsattr -h
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
File "/opt/salt/lib/python2.7/site-packages/salt/state.py", line 1905, in call
**cdata['kwargs'])
File "/opt/salt/lib/python2.7/site-packages/salt/loader.py", line 1830, in wrapper
return f(*args, **kwargs)
File "/opt/salt/lib/python2.7/site-packages/salt/states/file.py", line 4119, in replace
backslash_literal=backslash_literal)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 2420, in replace
check_perms(path, None, pre_user, pre_group, pre_mode)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 4460, in check_perms
lattrs = lsattr(name)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 573, in lsattr
results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0])
IndexError: list index out of range

# Fixed code
def _cmp_attrs(path, attrs):
    """
    .. versionadded:: 2018.3.0

    Compare attributes of a given file to given attributes.
    Returns a pair (list) where first item are attributes to
    add and second item are to be removed.

    Please take into account when using this function that some minions will
    not have lsattr installed.

    path
        path to file to compare attributes with.

    attrs
        string of attributes to compare against a given file
    """
    diff = [None, None]

    # lsattr for AIX is not the same thing as lsattr for linux.
    if salt.utils.platform.is_aix():
        return None

    try:
        lattrs = lsattr(path).get(path, "")
    except AttributeError:
        # lsattr not installed
        return None

    old = [chr for chr in lattrs if chr not in attrs]
    if len(old) > 0:
        diff[1] = "".join(old)

    new = [chr for chr in attrs if chr not in lattrs]
    if len(new) > 0:
        diff[0] = "".join(new)

    return diff