Bug 976242

Summary: hostname handling needs sanity improvement
Product: Red Hat Enterprise Linux 5 Reporter: Miroslav Hradílek <mhradile>
Component: sosAssignee: Bryn M. Reeves <bmr>
Status: CLOSED ERRATA QA Contact: Miroslav Hradílek <mhradile>
Severity: unspecified Docs Contact:
Priority: low    
Version: 5.9CC: agk, bmr, dkutalek, gavin, lmiksik, mhradile, prc
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: sos-1.7-9.65.el5 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 822174 Environment:
Last Closed: 2013-10-01 00:37:30 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: 822174    
Bug Blocks:    

Comment 1 Miroslav Hradílek 2013-06-20 08:03:41 UTC
Bug 822174 also affects RHEL-5 (5.9 reproduced)

# rpm -q sos
sos-1.7-9.62.el5

# hostname 'f/t_u-r:!§@#$%^&gt;._ha_*()=+"`;/\?~|}{][hěščÁŤh'

# hostname
f/t_u-r:!§@#$%^&gt;._ha_*()=+"`;/\?~|}{][hěščÁŤh

# sosreport --batch -o general

sosreport (version 1.7)

This utility will collect some detailed  information about the
hardware and  setup of your  Red Hat Enterprise Linux  system.
The information is collected and an archive is  packaged under
/tmp, which you can send to a support representative.
Red Hat will use this information for diagnostic purposes ONLY
and it will be considered confidential information.

This process may take a while to complete.
No changes will be made to your system.


 plugin general finished ...                   
 Completed.

Creating compressed archive...
/bin/mv: cannot move `/tmp/sos_QRLfBo' to `/tmp/f/t_u-r:!§@#$%^': No such file or directory
sh: gt: command not found
sh: -379509: command not found
/bin/mv: missing destination file operand after `/tmp/f/t_u-r:!§@#$%^'
Try `/bin/mv --help' for more information.
sh: gt: command not found
sh: -379509: command not found
Traceback (most recent call last):
  File "/usr/sbin/sosreport", line 734, in ?
    sosreport()
  File "/usr/sbin/sosreport", line 723, in sosreport
    policy.packageResults()
  File "/usr/lib/python2.4/site-packages/sos/policyredhat.py", line 201, in packageResults
    fp = open(os.path.join(ourtempdir, tarballName), "r")
IOError: [Errno 2] No such file or directory: '/tmp/sosreport-f/t_u-r:!\xc2\xa7@#$%^&gt;.tar.bz2'

Comment 2 Miroslav Hradílek 2013-06-20 11:37:12 UTC
Also related to this bug 771393.

Was sosreport in RHEL-5 ever capable of using info from
/etc/sysconfig/rhn/systemid ?

On sos-1.7-9.62.el5 it seems to ignore it entirely and use hostname instead.

On the same package, the sanitization seems to be in place although not consistent with RHEL-6. When crippled username (containing weird characters) is given using --name parameter it only outputs alphanumeric characters (no '-' dashes) unlike in RHEL-6.

Comment 4 RHEL Program Management 2013-06-24 10:38:56 UTC
This request was evaluated by Red Hat Product Management for inclusion
in a Red Hat Enterprise Linux release.  Product Management has
requested further review of this request by Red Hat Engineering, for
potential inclusion in a Red Hat Enterprise Linux release for currently
deployed products.  This request is not yet committed for inclusion in
a release.

Comment 6 Bryn M. Reeves 2013-07-24 13:24:25 UTC
This change brings hostname handling in line with rhel6:

- Strip all non-alphanumeric/dash characters
- If string is empty substitute 'default' (date/time will make unique)

# gendiff sos .orig
diff -up sos/policyredhat.py.orig sos/policyredhat.py
--- sos/policyredhat.py.orig	2013-07-23 17:13:46.000000000 +0100
+++ sos/policyredhat.py	2013-07-23 17:13:51.000000000 +0100
@@ -152,6 +152,7 @@ class SosPolicy:
                 sys.exit(0)
 
         if len(self.reportName) == 0:
+            localname = re.sub(r"[^_a-zA-Z.0-9-]", "", localname)
             self.reportName = localname
         
         if self.cInfo['cmdlineopts'].customerName:
@@ -162,6 +163,9 @@ class SosPolicy:
             self.ticketNumber = self.cInfo['cmdlineopts'].ticketNumber
             self.ticketNumber = re.sub(r"[^0-9]", "", self.ticketNumber)
 
+        if len(self.reportName) == 0:
+            self.reportName = "default"
+
         return
 
     def packageResults(self):

Comment 9 errata-xmlrpc 2013-10-01 00:37:30 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.

http://rhn.redhat.com/errata/RHBA-2013-1356.html