Skip to content

fix: source TemplateRenderError from canonical exceptions module (CodeQL #783) - #656

Open
ramseymcgrath wants to merge 1 commit into
mainfrom
codeql-critical-fixes
Open

fix: source TemplateRenderError from canonical exceptions module (CodeQL #783)#656
ramseymcgrath wants to merge 1 commit into
mainfrom
codeql-critical-fixes

Conversation

@ramseymcgrath

Copy link
Copy Markdown
Collaborator

Summary

Fixes the one real correctness bug surfaced during a triage of the GitHub code scanning (CodeQL) findings.

pcileech_generator.py imported TemplateRenderError from the pcileechfwgenerator.templating package, whose __init__ sets TemplateRenderError = None in its ImportError fallback (src/templating/__init__.py:19-22). If that fallback ever triggers, the handler at pcileech_generator.py:698 becomes except None, which raises TypeError at exception-match time and masks the real SystemVerilog-generation error (CodeQL alert #783, py/useless-except).

The fix imports TemplateRenderError from pcileechfwgenerator.exceptions, where it is defined unconditionally. It is the same class object that template_renderer actually raises (template_renderer.py:16 imports it from exceptions), so exception matching is unchanged — the name simply can never be None again.

Changes

  • src/device_clone/pcileech_generator.py — move TemplateRenderError from the templating import to the exceptions import.
  • tests/test_pcileech_generator_template_error_import.py — regression test that reproduces the templating ImportError fallback (templating.TemplateRenderError = None) and asserts the handler name stays a valid exception class.

Verification

  • Regression test fails before the fix (TemplateRenderError became None) and passes after — TDD-confirmed.
  • All 61 related pcileech_generator / template_renderer tests 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:

  • #1098 base.py:129 (wrong-arguments) — call arity is satisfied; only a redundant double-format.
  • fix validation #252 attribute_access.py:198 (hash-unhashable) — dominated by an explicit isinstance(..., Hashable) guard.
  • #702-705, #1059-1060 string_utils.py (shell-command-constructed-from-input) — pure logging/formatting helpers; no output reaches a shell (safe_format returns text; no shell=True/os.system/os.popen anywhere).

Separately, two create_subprocess_shell sites (system_status.py, build_orchestrator.py) are a defense-in-depth hardening opportunity to restore the documented argv-only invariant — out of scope here.

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.
Copilot AI lite review requested due to automatic review settings August 15, 2026 06:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 TemplateRenderError from pcileechfwgenerator.exceptions (where it is always defined) instead of from pcileechfwgenerator.templating (where it can be set to None under fallback).
  • Add a regression test that simulates templating.TemplateRenderError = None and asserts pcileech_generator.TemplateRenderError remains 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

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants