Skip to content

Commit

Permalink
[policies] Fix bug in distro identification
Browse files Browse the repository at this point in the history
Fixes a bug in #3764.

A bug in the distro-identifying logic caused incorrect identification
of the distro as CentOS, Fedora, or RHEL under the following conditions:

1. Distro inherits RedHatPolicy
2. Distro has either of /etc/{centos,fedora,redhat}-release
3. Policy file appears earlier than redhat.py in dictionary order

The issue occurs because the distro-identifying logic relies on the
existence of the above os_release_file without examining its contents,
more than checking NAME or ID in the /etc/os-release file. As a result,
once /etc/{centos,fedora,redhat}-release is found, the contents of
/etc/os-release are never checked, leading to distro misidentification.

At least AlmaLinux is affected by this bug.

Signed-off-by: Koichiro Iwao <[email protected]>
  • Loading branch information
metalefty authored and arif-ali committed Dec 13, 2024
1 parent 279ea13 commit 5f06a1b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sos/policies/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def _check_release(content):
if remote:
return _check_release(remote)
# use the os-specific file primarily
if os.path.isfile(cls.os_release_file):
# also check the symlink destination
if (os.path.isfile(cls.os_release_file) and
os.path.basename(cls.os_release_file)
== os.path.basename(os.path.realpath(cls.os_release_file))):
return True
# next check os-release for a NAME or ID value we expect
with open(OS_RELEASE, "r", encoding='utf-8') as f:
Expand Down

0 comments on commit 5f06a1b

Please sign in to comment.