Bug 1698763

Summary: pcs exits with traceback when port with invalid value was given to the auth command
Product: Red Hat Enterprise Linux 8 Reporter: Miroslav Lisik <mlisik>
Component: pcsAssignee: Miroslav Lisik <mlisik>
Status: CLOSED ERRATA QA Contact: cluster-qe <cluster-qe>
Severity: unspecified Docs Contact:
Priority: medium    
Version: 8.0CC: cfeist, cluster-maint, idevat, mmazoure, omular, tojeline
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: pcs-0.10.3-1.el8 Doc Type: Bug Fix
Doc Text:
Cause: The `pcs host auth` command does not validate network port. Consequence: Python traceback is propagated to the user in the case when invalid port was given. Fix: Catch an exeption in case when port is invalid and display proper error message to the user. Result: The user is informed about invalid port by error message and proper port range is displayed.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-28 15:27:56 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:
Attachments:
Description Flags
proposed fix none

Description Miroslav Lisik 2019-04-11 08:17:17 UTC
Description of problem:
Pcs exits with traceback when port with invalid value was given to the auth command.

Version-Release number of selected component (if applicable):
pcs-0.10.1-4.el8

How reproducible:
always

Steps to Reproduce:
1. run auth command with some invalid port value

[root@virt-157 ~]# pcs host auth node-01 -u hacluster -p password addr=virt-157.cluster-qe.lab.eng.brq.redhat.com:70000
Traceback (most recent call last):
  File "/usr/sbin/pcs", line 11, in <module>
    load_entry_point('pcs==0.10.1', 'console_scripts', 'pcs')()
  File "/usr/lib/python3.6/site-packages/pcs/app.py", line 178, in main
    utils.get_input_modifiers(),
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 22, in host_cmd
    auth_cmd(lib, argv_next, modifiers)
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 73, in auth_cmd
    "host name"
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 71, in <dictcomp>
    for host, opts in parse_args.split_list_by_any_keywords(
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 45, in _parse_host_options
    addr, port = _parse_addr(parsed_options.get(ADDR_OPT_KEYWORD, host))
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 55, in _parse_addr
    return url.hostname, (url.port if url.port else settings.pcsd_default_port)
  File "/usr/lib64/python3.6/urllib/parse.py", line 171, in port
    raise ValueError("Port out of range 0-65535")
ValueError: Port out of range 0-65535
[root@virt-157 ~]# echo $?
1
[root@virt-157 ~]# pcs host auth node-01 -u hacluster -p password addr=virt-157.cluster-qe.lab.eng.brq.redhat.com:port
Traceback (most recent call last):
  File "/usr/sbin/pcs", line 11, in <module>
    load_entry_point('pcs==0.10.1', 'console_scripts', 'pcs')()
  File "/usr/lib/python3.6/site-packages/pcs/app.py", line 178, in main
    utils.get_input_modifiers(),
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 22, in host_cmd
    auth_cmd(lib, argv_next, modifiers)
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 73, in auth_cmd
    "host name"
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 71, in <dictcomp>
    for host, opts in parse_args.split_list_by_any_keywords(
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 45, in _parse_host_options
    addr, port = _parse_addr(parsed_options.get(ADDR_OPT_KEYWORD, host))
  File "/usr/lib/python3.6/site-packages/pcs/host.py", line 55, in _parse_addr
    return url.hostname, (url.port if url.port else settings.pcsd_default_port)
  File "/usr/lib64/python3.6/urllib/parse.py", line 169, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'port'
[root@virt-157 ~]# echo $?
1

Actual results:
pcs exits with a traceback.

Expected results:
pcs exits with some error message.

Additional info:

Comment 2 Miroslav Lisik 2019-10-16 16:12:59 UTC
Created attachment 1626534 [details]
proposed fix

Test:
1. Use some port out of range with address specified in `pcs auth host` command.
2. Error message should be displayed instead of python traceback.

[root@r81-node-01 pcs]# lpcs host auth node-001 -u hacluster -p password addr=virt-001.cluster-qe.lab.eng.brq.redhat.com:65536
Error: Invalid port number in address 'virt-001.cluster-qe.lab.eng.brq.redhat.com:65536', use 1..65535
[root@r81-node-01 pcs]# lpcs host auth node-001 -u hacluster -p password addr=virt-001.cluster-qe.lab.eng.brq.redhat.com:notaportnumber
Error: Invalid port number in address 'virt-001.cluster-qe.lab.eng.brq.redhat.com:notaportnumber', use 1..65535

Comment 3 Miroslav Lisik 2019-10-23 15:30:55 UTC
After fix:

[root@r81-node-01 ~]# rpm -q pcs
pcs-0.10.3-1.el8.x86_64


[root@r81-node-01 ~]# pcs host auth -u hacluster -p password r81-node-01 addr=r81-node-01:65536
Error: Invalid port number in address 'r81-node-01:65536', use 1..65535
[root@r81-node-01 ~]# echo $?
1
[root@r81-node-01 ~]# pcs host auth -u hacluster -p password r81-node-01 addr=r81-node-01:65535 r81-node-02 addr=192.168.122.82:string
Error: Invalid port number in address '192.168.122.82:string', use 1..65535
[root@r81-node-01 ~]# echo $?
1

Comment 7 errata-xmlrpc 2020-04-28 15:27:56 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-2020:1568