Skip to content

fix(isotp): wake receivers when the reader fails on an exception the generic-catch filter excludes - #268

Merged
dborgards merged 2 commits into
mainfrom
alert-autofix-468
Oct 3, 2026
Merged

dborgards merged 2 commits into
mainfrom
alert-autofix-468

Conversation

@dborgards

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/dborgards/CanKit.Pro/security/code-scanning/468

Use a filtered catch instead of a fully generic catch in RunReaderAsync so only non-fatal exceptions are treated as subscription loss.

Best fix in this snippet:

  • In src/CanKit.Pro.IsoTp/IsoTpChannel.cs, within RunReaderAsync, replace:
    • catch (Exception ex)
  • With:
    • catch (Exception ex) when (ex is not OutOfMemoryException and not StackOverflowException and not AccessViolationException and not AppDomainUnloadedException and not BadImageFormatException and not CannotUnloadAppDomainException and not ThreadAbortException)

Why this is best here:

  • Keeps existing behavior for expected runtime failures (still captures and propagates them as lost).
  • Avoids catching critical/fatal exceptions that should not be handled as normal subscription loss.
  • Requires no new imports, no structural refactor, and minimal code change localized to the flagged region.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@dborgards
dborgards marked this pull request as ready for review October 3, 2026 16:20
@cursor

cursor Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes exception handling on the ISO-TP subscription reader thread, which gates all inbound traffic and ReceiveAsync completion; behavior is tightened for rare fatal exceptions but is covered by new tests.

Overview
Addresses code-scanning alert on a generic catch in RunReaderAsync by using exception filters so only non-fatal subscription failures are handled like ordinary “subscription lost” errors.

For fatal reader failures (e.g. OutOfMemoryException, BadImageFormatException) that must not be swallowed, the reader now publishes inbox loss first via a new PublishSubscriptionLoss helper, then rethrows so ReceiveAsync waiters and later receives still see the same fault and the background reader task still faults (fixing a hang when those exceptions bypassed loss signaling).

Adds an integration theory test that simulates excluded reader failures and asserts both concurrent and subsequent receives, BackgroundExceptionOccurred, and _readerTask all observe the same exception instance.

Reviewed by Cursor Bugbot for commit c660fd2. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T16:22:26.803451Z 178a801 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 178a801920

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/CanKit.Pro.IsoTp/IsoTpChannel.cs
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…generic-catch filter excludes

The filter that closed the generic-catch alert let those exceptions fault the
reader task without publishing inbox loss. Publish the same loss first, then
rethrow, so ReceiveAsync wakes and the task still faults.

Co-authored-by: Dietmar Borgards <dborgards@users.noreply.github.com>
@cursor cursor Bot changed the title Potential fix for code scanning alert no. 468: Generic catch clause fix(isotp): wake receivers when the reader fails on an exception the generic-catch filter excludes Oct 3, 2026
@dborgards
dborgards merged commit 87dff12 into main Oct 3, 2026
14 checks passed
@dborgards
dborgards deleted the alert-autofix-468 branch October 3, 2026 16:54
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.

2 participants