python/semanage: check variable type of port before trying to split

While using Ansible's Selinux module to manage ports, I discovered
that numerical ports caused an unhandled exception in 'seobject.py'.
This appears to be a bug, and I am proposing a fix which checks the
type of the argument before operating on it.  This maintains the
original functionality in the case of a string, and acts in the same
fashion if you supply an integer.

I did not find any open bug report against the SELinux project. The
downstream bug report is here:
https://github.com/ansible/ansible/issues/60968

Signed-off-by: Joshua Schmidlkofer <joshua@joshuainnovates.us>
This commit is contained in:
Joshua Schmidlkofer 2019-12-06 16:17:44 -08:00 committed by Stephen Smalley
parent dca7ce8195
commit 5bbe32a7e5

View File

@ -1070,7 +1070,11 @@ class portRecords(semanageRecords):
if port == "":
raise ValueError(_("Port is required"))
ports = port.split("-")
if isinstance(port, str):
ports = port.split('-', 1)
else:
ports = (port,)
if len(ports) == 1:
high = low = int(ports[0])
else: