Skip to content

Conversation

sanketsaurav
Copy link
Contributor

Changes:

  • Fixed mutable default arguments used in cve_bin_tool/csv2cve.py and cve_bin_tool/cli.py
  • Removed unused imports in cve_bin_tool/cli.py, cve_bin_tool/checkers/openssh.py and cve_bin_tool/NVDAutoUpdate.py
  • Use raw strings in cve_bin_tool/checkers/openssh.py, cve_bin_tool/NVDAutoUpdate.py and cve_bin_tool/checkers/expat.py
  • Replaced range(len(..)) with enumerate() in cve_bin_tool/cli.py

Some more issues on the repo's DeepSource dashboard on my fork here.

Changes:
 - Fixed mutable default arguments used in `cve_bin_tool/csv2cve.py` and `cve_bin_tool/cli.py`
 - Removed unused imports in `cve_bin_tool/cli.py`, `cve_bin_tool/checkers/openssh.py` and `cve_bin_tool/NVDAutoUpdate.py`
 - Use raw strings in `cve_bin_tool/checkers/openssh.py`, `cve_bin_tool/NVDAutoUpdate.py` and `cve_bin_tool/checkers/expat.py`
 - Replaced `range(len(..))` with `enumerate()` in `cve_bin_tool/cli.py`
def main(argv=None, outfile=sys.stdout):
""" Scan a binary file for certain open source libraries that may have CVEs """
if argv is None:
argv = sys.argv

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this change?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your comment says this makes it not mutable, what do you mean by this? My understanding is that this changes preserves mutability. If we wished to make changes to argv not change sys.argv, we'd have to use copy.deepcopy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to sys.argv being passed as a default argument in the function definition (on line 292).

def main(argv=sys.argv, outfile=sys.stdout):
    ...

It's not recommended to pass mutable objects as default values since the latest passed value is preserved on subsequent function calls, and can cause unintended effects. (ref)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay I see what you mean, cool!

#!/usr/bin/python3
# pylint: disable=anomalous-backslash-in-string, invalid-name
"""
r"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want a r prefix on this docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an unescaped backslash in the docstring on line 16. Adding another backslash to escape it can change the meaning, which is why we can convert the docstring to a raw string.

@johnandersen777
Copy link

Thanks!

@sanketsaurav
Copy link
Contributor Author

@pdxjohnny Replied to the comments.

@terriko terriko merged commit 4ad5ceb into intel:master Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants