Skip to content

Fix UnboundLocalError in curl importer for non-SEMVER version ranges - #2214

Open
xovishnukosuri wants to merge 1 commit into
aboutcode-org:mainfrom
xovishnukosuri:fix-curl-importer-unbound-variable
Open

xovishnukosuri wants to merge 1 commit into
aboutcode-org:mainfrom
xovishnukosuri:fix-curl-importer-unbound-variable

Conversation

@xovishnukosuri

Copy link
Copy Markdown

Fixes #1166

Summary

  • parse_curl_advisory conditionally assigned fixed_version_range inside if version_type == "SEMVER" and fixed_version: but then passed it to AffectedPackageV2 unconditionally. Any advisory with only a GIT range (no SEMVER block) or no fixed event raises UnboundLocalError.
  • Changed the empty fallback for affected and ranges from [] to {} so subsequent .get() calls don't raise AttributeError on a list when the feed returns an empty affected array.
  • Added fixed_version_range = None before the conditional so non-SEMVER advisories correctly store None for the fixed version range.

Changes

  • vulnerabilities/pipelines/v2_importers/curl_importer.py: initialize fixed_version_range = None before the SEMVER conditional; use {} instead of [] as the fallback for empty affected and ranges.
  • vulnerabilities/tests/pipelines/v2_importers/test_curl_importer_v2.py: two new tests - one for GIT-only ranges (regression test for the UnboundLocalError) and one for the CURL-CVE-* advisory id format used by the actual feed.

Test plan

  • python -m pytest vulnerabilities/tests/pipelines/v2_importers/test_curl_importer_v2.py -v — all 8 tests pass
  • New test test_parse_curl_advisory_git_only_range would have failed on the old code with UnboundLocalError: local variable 'fixed_version_range' referenced before assignment

🤖 Generated with Claude Code

parse_curl_advisory only assigned fixed_version_range inside an if block
but referenced it unconditionally, causing UnboundLocalError for advisories
that have only a GIT range or no fixed version. Initialize it to None
before the conditional. Also change the empty fallbacks for affected and
ranges from [] to {} so .get() calls later do not raise AttributeError.

Adds two new tests covering GIT-only ranges and the CURL-CVE-* id format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Add CURL advisories data source

1 participant