Bug 1632251

Summary: unpackaged false positives and eventual traceback
Product: Red Hat Enterprise Linux 7 Reporter: Filip Krska <fkrska>
Component: sosAssignee: Pavel Moravec <pmoravec>
Status: CLOSED ERRATA QA Contact: Miroslav HradĂ­lek <mhradile>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.7CC: agk, bmr, cww, fkrska, gavin, hannsj_uhl, mhradile, plambri, sbradley, yferszt
Target Milestone: rcKeywords: Patch, Reproducer
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: sos-3.7-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1632607 (view as bug list) Environment:
Last Closed: 2019-08-06 13:15:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1594286, 1632607, 1648022    

Description Filip Krska 2018-09-24 13:11:02 UTC
Description of problem:

unpackaged reports false positives
unpackaged crashes if no unpackaged (or false positives) file found

Version-Release number of selected component (if applicable):

sos-3.6-7.el7.noarch

How reproducible:

Always

Steps to Reproduce:

1. # sosreport --batch --build -o unpackaged


Actual results:

false positives are found

sort -u /var/tmp/sosreport-.../sos_strings/unpackaged/unpackaged|wc -l
10

Expected results:

no false positives are found on clean install

Additional info:

some rpms doesn't list paths without '/usr' (notice to maintainers needed?)

skip_paths = ["/bin/rpm", "/bin/mailx"] in redhat.py:mangle_package_path() is not complete

proof-of-concept patch

--- sos/plugins/unpackaged.py.orig	2018-09-24 08:13:07.047477426 -0400
+++ sos/plugins/unpackaged.py	2018-09-24 08:51:41.899477426 -0400
@@ -74,7 +74,8 @@ class Unpackaged(Plugin, RedHatPlugin):
 
         for d in get_env_path_list():
             all_fsystem += all_files_system(d)
-        not_packaged = [x for x in all_fsystem if x not in all_frpm]
+        not_packaged = [x for x in all_fsystem
+            if x not in all_frpm and "/usr" + x not in all_frpm]
         not_packaged_expanded = format_output(not_packaged)
         self.add_string_as_file('\n'.join(not_packaged_expanded), 'unpackaged')

prevents false positives

if the list is empty (expected on clean install) plugin crashes with

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/sos/sosreport.py", line 1116, in collect_plugin
    plug.collect()
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 949, in collect
    self._collect_strings()
  File "/usr/lib/python2.7/site-packages/sos/plugins/__init__.py", line 930, in _collect_strings
    content = string.splitlines()[0]
IndexError: list index out of range

this can be fixed with

--- sos/plugins/__init__.py.orig	2018-09-24 08:51:07.598477426 -0400
+++ sos/plugins/__init__.py	2018-09-24 08:51:30.877477426 -0400
@@ -725,7 +725,8 @@ class Plugin(object):
     def add_string_as_file(self, content, filename):
         """Add a string to the archive as a file named `filename`"""
         self.copy_strings.append((content, filename))
-        content = content.splitlines()[0]
+        # empty content has no first line
+        if content: content = content.splitlines()[0]
         if not isinstance(content, six.string_types):
             content = content.decode('utf8', 'ignore')
         self._log_debug("added string ...'%s' as '%s'" % (content, filename))
@@ -927,7 +928,8 @@ class Plugin(object):
 
     def _collect_strings(self):
         for string, file_name in self.copy_strings:
-            content = string.splitlines()[0]
+            # empty string has no first line
+            content = string.splitlines()[0] if string else string
             if not isinstance(content, six.string_types):
                 content = content.decode('utf8', 'ignore')
             self._log_info("collecting string ...'%s' as '%s'"

Comment 1 Pavel Moravec 2018-09-24 14:42:33 UTC
The later has upstream PR inside #1422, 

https://github.com/sosreport/sos/pull/1422/commits/4280f7db3e231ce94b3141ee7358c726fe3c9100

in particular.

The former: the problem seems to be elsewhere, as on my system I have in the sos_strings/unpackaged/unpackaged files like:

1)
/bin/systemctl - this is due to:
# rpm -ql systemd | grep /bin/systemctl
/usr/bin/systemctl
#
while /bin is a symlink to /usr/bin we dont expand.

2)
/bin/tracepath6 - b'cos all_frpm collects /usr/sbin/tracepath6 (that is a symlink to /bin/tracepath6), instead of the symlink target itself - so opposite problem to 1)

I.e. we have to collect and compare "readlink -f .." when building all_frpm and all_files_system(d).

Comment 2 Pavel Moravec 2018-09-24 14:53:56 UTC
The second shall be fixed by patch:

--- /usr/lib/python2.7/site-packages/sos/plugins/unpackaged.py	2018-09-14 22:37:50.000000000 +0200
+++ /usr/lib/python2.7/site-packages/sos/plugins/unpackaged.py-new	2018-09-24 16:51:33.066456699 +0200
@@ -51,9 +51,9 @@ class Unpackaged(Plugin, RedHatPlugin):
                             path = os.path.abspath(os.readlink(path))
                     except Exception:
                         continue
-                    file_list.append(path)
+                    file_list.append(os.path.realpath(path))
                 for name in dirs:
-                    file_list.append(os.path.join(root, name))
+                    file_list.append(os.path.realpath(os.path.join(root, name)))
 
             return file_list
 
@@ -69,7 +69,8 @@ class Unpackaged(Plugin, RedHatPlugin):
             return expanded
 
         all_fsystem = []
-        all_frpm = set(self.policy.mangle_package_path(
+        all_frpm = set(os.path.realpath(x) 
+		       for x in self.policy.mangle_package_path(
                        self.policy.package_manager.files))
 
         for d in get_env_path_list():


Filip, can you please try it? Or provide access to the system you see some remaining problem (after applying this patch and other than the string.splitlines()[0])?

Comment 3 Filip Krska 2018-09-24 15:15:51 UTC
Yep, your patches appear to work as well in my env.

Comment 4 Pavel Moravec 2019-02-15 07:59:07 UTC
(POSTed to upstream some time ago already)

Comment 9 errata-xmlrpc 2019-08-06 13:15:20 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2019:2295