From 28d75dd73e3269c95616688cdc4b41c788058791 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 19 Dec 2023 09:08:59 +0100 Subject: [PATCH 1/5] Fix: Make explicit/implicit returns consistent The check_command_status function will now always explicitly return False unless the check succeeds while the non-None return from _ssh_authentication_input_loop has been removed. --- gvm/connections.py | 2 +- gvm/utils.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gvm/connections.py b/gvm/connections.py index 576888a6c..9d72e774a 100644 --- a/gvm/connections.py +++ b/gvm/connections.py @@ -313,7 +313,7 @@ def _ssh_authentication_input_loop( save = input() break elif add == "no": - return sys.exit( + sys.exit( "User denied key. Host key verification failed." ) else: diff --git a/gvm/utils.py b/gvm/utils.py index f76ec9ec6..03bd39d72 100644 --- a/gvm/utils.py +++ b/gvm/utils.py @@ -66,10 +66,13 @@ def check_command_status(xml: str) -> bool: except KeyError: print(logger) logger.error("Not received an status code within the response.") + return False except etree.Error as e: logger.error("etree.XML(xml): %s", e) return False + return False + def to_dotted_types_dict(types: List) -> TypesDict: """Create a dictionary accessible via dot notation""" From fd3e3a2ba109ff77f6fea190cacd3374d1579e87 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 19 Dec 2023 09:26:07 +0100 Subject: [PATCH 2/5] Fix: Remove unused variables for add_element returns Some unused local variables holding the return values from add_element calls are removed. --- gvm/protocols/gmpv208/entities/filter.py | 2 +- gvm/protocols/gmpv208/entities/tickets.py | 4 ++-- gvm/protocols/ospv1.py | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gvm/protocols/gmpv208/entities/filter.py b/gvm/protocols/gmpv208/entities/filter.py index 24c3c586a..dfed9697e 100644 --- a/gvm/protocols/gmpv208/entities/filter.py +++ b/gvm/protocols/gmpv208/entities/filter.py @@ -131,7 +131,7 @@ def create_filter( ) cmd = XmlCommand("create_filter") - _xmlname = cmd.add_element("name", name) + cmd.add_element("name", name) if comment: cmd.add_element("comment", comment) diff --git a/gvm/protocols/gmpv208/entities/tickets.py b/gvm/protocols/gmpv208/entities/tickets.py index 07a5fbc53..1dfe29cfa 100644 --- a/gvm/protocols/gmpv208/entities/tickets.py +++ b/gvm/protocols/gmpv208/entities/tickets.py @@ -66,7 +66,7 @@ def clone_ticket(self, ticket_id: str) -> Any: cmd = XmlCommand("create_ticket") - _copy = cmd.add_element("copy", ticket_id) + cmd.add_element("copy", ticket_id) return self._send_xml_command(cmd) @@ -114,7 +114,7 @@ def create_ticket( _user = _assigned.add_element("user") _user.set_attribute("id", assigned_to_user_id) - _note = cmd.add_element("open_note", note) + cmd.add_element("open_note", note) if comment: cmd.add_element("comment", comment) diff --git a/gvm/protocols/ospv1.py b/gvm/protocols/ospv1.py index 1ece8f720..3f279dc06 100644 --- a/gvm/protocols/ospv1.py +++ b/gvm/protocols/ospv1.py @@ -63,7 +63,7 @@ def create_vt_selection_element(_xmlvtselection, vt_selection): _xmlvt.add_element("vt_value", value, attrs={"id": key}) elif vt_id == "vt_groups" and isinstance(vt_values, list): for group in vt_values: - _xmlvt = _xmlvtselection.add_element( + _xmlvtselection.add_element( "vt_group", attrs={"filter": group} ) else: @@ -252,9 +252,8 @@ def start_scan( _xmltarget.add_element("hosts", hosts) _xmltarget.add_element("ports", ports) if credentials: - _xmlcredentials = _xmltarget.add_element("credentials") _xmlcredentials = create_credentials_element( - _xmlcredentials, credentials + _xmltarget.add_element("credentials"), credentials ) # Check target as attribute for legacy mode compatibility. Deprecated. elif target: @@ -267,9 +266,8 @@ def start_scan( ) if vt_selection: - _xmlvtselection = cmd.add_element("vt_selection") _xmlvtselection = create_vt_selection_element( - _xmlvtselection, vt_selection + cmd.add_element("vt_selection"), vt_selection ) return self._send_xml_command(cmd) From e5cebd5d309fc1c1f054b8be114ae2d3ba6d1793 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 19 Dec 2023 09:40:56 +0100 Subject: [PATCH 3/5] Fix: Add InvalidArgumentType superclass init The class InvalidArgumentType now explicitly calls the superclass initializer, making it more explict that the message is set to None. --- gvm/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gvm/errors.py b/gvm/errors.py index cad7b0ddb..ca042e2ee 100644 --- a/gvm/errors.py +++ b/gvm/errors.py @@ -150,7 +150,7 @@ def __init__( *, function: Optional[str] = None, ): - # pylint: disable=super-init-not-called + super().__init__(None) self.argument = argument self.function = function self.arg_type = arg_type From 64d9c009bd257cdaa64ef80982753fceaac83625 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 19 Dec 2023 10:14:22 +0100 Subject: [PATCH 4/5] Remove unreachable return MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Björn Ricks --- gvm/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gvm/utils.py b/gvm/utils.py index 03bd39d72..3f8902fa1 100644 --- a/gvm/utils.py +++ b/gvm/utils.py @@ -71,7 +71,6 @@ def check_command_status(xml: str) -> bool: logger.error("etree.XML(xml): %s", e) return False - return False def to_dotted_types_dict(types: List) -> TypesDict: From a024d3c9d556b75cb2e09961ed284eb93c9d1168 Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Tue, 19 Dec 2023 10:17:01 +0100 Subject: [PATCH 5/5] Fix formatting --- gvm/connections.py | 4 +--- gvm/protocols/ospv1.py | 4 +--- gvm/utils.py | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/gvm/connections.py b/gvm/connections.py index 9d72e774a..be4bff82d 100644 --- a/gvm/connections.py +++ b/gvm/connections.py @@ -313,9 +313,7 @@ def _ssh_authentication_input_loop( save = input() break elif add == "no": - sys.exit( - "User denied key. Host key verification failed." - ) + sys.exit("User denied key. Host key verification failed.") else: print("Please type 'yes' or 'no': ", end="") add = input() diff --git a/gvm/protocols/ospv1.py b/gvm/protocols/ospv1.py index 3f279dc06..00c3a6313 100644 --- a/gvm/protocols/ospv1.py +++ b/gvm/protocols/ospv1.py @@ -63,9 +63,7 @@ def create_vt_selection_element(_xmlvtselection, vt_selection): _xmlvt.add_element("vt_value", value, attrs={"id": key}) elif vt_id == "vt_groups" and isinstance(vt_values, list): for group in vt_values: - _xmlvtselection.add_element( - "vt_group", attrs={"filter": group} - ) + _xmlvtselection.add_element("vt_group", attrs={"filter": group}) else: raise InvalidArgument( f"It was not possible to add {vt_id} to the VTs selection." diff --git a/gvm/utils.py b/gvm/utils.py index 3f8902fa1..caab74bd7 100644 --- a/gvm/utils.py +++ b/gvm/utils.py @@ -72,7 +72,6 @@ def check_command_status(xml: str) -> bool: return False - def to_dotted_types_dict(types: List) -> TypesDict: """Create a dictionary accessible via dot notation""" dic = {}