fix: source TemplateRenderError from canonical exceptions module (CodeQL #783) - #656
Open
ramseymcgrath wants to merge 1 commit into
Open
fix: source TemplateRenderError from canonical exceptions module (CodeQL #783)#656ramseymcgrath wants to merge 1 commit into
ramseymcgrath wants to merge 1 commit into
Conversation
CodeQL #783 (py/useless-except) flagged the `except TemplateRenderError` handler in pcileech_generator. The name was imported from the templating package, whose __init__ sets `TemplateRenderError = None` on its ImportError fallback. In that degraded state the handler becomes `except None`, raising TypeError at match time and masking the real SystemVerilog-generation error. Import TemplateRenderError from pcileechfwgenerator.exceptions, where it is defined unconditionally and is the same class template_renderer raises, so it can never be None. Adds a regression test that reproduces the fallback.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a real correctness issue in the PCIe firmware generation orchestrator (pcileech_generator) where an except TemplateRenderError handler could become except None if pcileechfwgenerator.templating fell back on its ImportError path, masking the underlying SystemVerilog generation error (CodeQL #783).
Changes:
- Import
TemplateRenderErrorfrompcileechfwgenerator.exceptions(where it is always defined) instead of frompcileechfwgenerator.templating(where it can be set toNoneunder fallback). - Add a regression test that simulates
templating.TemplateRenderError = Noneand assertspcileech_generator.TemplateRenderErrorremains a valid exception class and matches the canonical exception type.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/device_clone/pcileech_generator.py |
Sources TemplateRenderError from the canonical exceptions module to prevent except None failures under templating fallback. |
tests/test_pcileech_generator_template_error_import.py |
Adds a regression test covering the degraded templating-package state and ensuring exception matching remains correct. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the one real correctness bug surfaced during a triage of the GitHub code scanning (CodeQL) findings.
pcileech_generator.pyimportedTemplateRenderErrorfrom thepcileechfwgenerator.templatingpackage, whose__init__setsTemplateRenderError = Nonein itsImportErrorfallback (src/templating/__init__.py:19-22). If that fallback ever triggers, the handler atpcileech_generator.py:698becomesexcept None, which raisesTypeErrorat exception-match time and masks the real SystemVerilog-generation error (CodeQL alert #783,py/useless-except).The fix imports
TemplateRenderErrorfrompcileechfwgenerator.exceptions, where it is defined unconditionally. It is the same class object thattemplate_rendereractually raises (template_renderer.py:16imports it fromexceptions), so exception matching is unchanged — the name simply can never beNoneagain.Changes
src/device_clone/pcileech_generator.py— moveTemplateRenderErrorfrom thetemplatingimport to theexceptionsimport.tests/test_pcileech_generator_template_error_import.py— regression test that reproduces the templatingImportErrorfallback (templating.TemplateRenderError = None) and asserts the handler name stays a valid exception class.Verification
TemplateRenderError became None) and passes after — TDD-confirmed.pcileech_generator/template_renderertests pass; no regressions.Triage notes (not in this PR)
The remaining critical-level CodeQL alerts were reviewed and determined to be false positives, to be dismissed on GitHub rather than code-changed:
base.py:129(wrong-arguments) — call arity is satisfied; only a redundant double-format.attribute_access.py:198(hash-unhashable) — dominated by an explicitisinstance(..., Hashable)guard.string_utils.py(shell-command-constructed-from-input) — pure logging/formatting helpers; no output reaches a shell (safe_formatreturns text; noshell=True/os.system/os.popenanywhere).Separately, two
create_subprocess_shellsites (system_status.py,build_orchestrator.py) are a defense-in-depth hardening opportunity to restore the documented argv-only invariant — out of scope here.