Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: AttributeError: 'NoneType' object has no attribute 'translate' when providing invalid purl #3478

Closed
weichslgartner opened this issue Oct 26, 2023 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@weichslgartner
Copy link
Contributor

Description

Console output crashes while printing Products with No Identified Vulnerabilities Table if given an invalid purl which then result in a None version.

To reproduce

Steps to reproduce the behaviour:

  1. Use this SBOM:
{
  "bomFormat": "CycloneDX",
  "specVersion": "1.5",
  "version": 1,
  "components": [
    {
      "name": "invalid_purl_package",
      "version": "1.1.0",
      "type": "library",
      "purl": "pkg:xxx/xxx/xxx"
    }
  ]
}
  1. Scan this SBOM with cve-bin-tool: cve-bin-tool --sbom cyclonedx --sbom-file minimal_example.json
  2. Crashes with attribute error AttributeError: 'NoneType' object has no attribute 'translate' when trying to output
│ /home/andreas/mambaforge/envs/cve-bin/lib/python3.9/site-packages/cve_bin_tool/output_engine/con │                                                                                                         
│ sole.py:335 in _output_console_nowrap                                                            │                                                                                                         
│                                                                                                  │                                                                                                         
│   332 │   │   │   │   cells = [                                                                  │                                                                                                         
│   333 │   │   │   │   │   Text.styled(product_data.vendor, color),                               │                                                                                                         
│   334 │   │   │   │   │   Text.styled(product_data.product, color),                              │                                                                                                         
│ ❱ 335 │   │   │   │   │   Text.styled(product_data.version, color),                              │                                                                                                         
│   336 │   │   │   │   ]                                                                          │                                                                                                         
│   337 │   │   │   │   table.add_row(*cells)                                                      │                                                                                                         
│   338 │   │   # Print the table to the console 

as version is product_data.version is None

{ProductInfo(vendor='UNKNOWN', product='xxx', version=None): 0}

Expected behabiour:
Just print empty table and ignore invalid purl.

Actual behaviour:
Crash with AttributeError

Version/platform info

Version of CVE-bin-tool( e.g. output of cve-bin-tool --version):
Installed from pypi or github?
3.2.2dev0 (installed from Github e58be27)

Operating system: Linux/Windows (other platforms are unsupported but feel free to report issues anyhow)
Linux andreas-VirtualBox 5.15.0-78-generic #85~20.04.1-Ubuntu SMP Mon Jul 17 09:42:39 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Python 3.9.16
Running in any particular CI environment we should know about? no

Anything else?

Happy to help with an PR, but unsure where to fix the issue, checking before printing or in the context of purl parsing.

@weichslgartner weichslgartner added the bug Something isn't working label Oct 26, 2023
@terriko
Copy link
Contributor

terriko commented Oct 30, 2023

Looks like we need probably an if statement checking for none somewhere.

I'd start by putting it in the printing since that's where the error is occurring and probably if we can't find a purl it's somewhat reasonable to have a None-type in there somewhere. But the purl parsing itself is relatively new so we could need some tweaking there too. here's the PR that added it, which should narrow down the search of where to put a fix: fa8e6d8

@terriko terriko added this to the 3.3 milestone Oct 30, 2023
weichslgartner added a commit to weichslgartner/cve-bin-tool that referenced this issue Oct 30, 2023
weichslgartner added a commit to weichslgartner/cve-bin-tool that referenced this issue Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants