Skip to content

Harden generator against malformed macro and uuid inputs#720

Merged
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-generator-robustness-guards
Jul 13, 2026
Merged

Harden generator against malformed macro and uuid inputs#720
tannergooding merged 2 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-generator-robustness-guards

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes a small set of verified latent robustness/correctness gaps in the managed generator. All are behavior-preserving for valid input.

  • Guard empty macro token arrays -- VisitMacroDefinitionRecord dereferenced tokens[0] before any length check, throwing IndexOutOfRangeException for macros with an empty extent (e.g. command-line/builtin macros). Now returns gracefully when tokens.Length == 0.
  • Bounds-check the uuid attribute text split -- TryGetUuid indexed [1] on the split result with no bounds check, crashing before the existing Guid.TryParse fallback could run when the attribute source has no double-quoted string. Now emits a Warning diagnostic and returns false.
  • Fix swapped int32-range comments in VisitIntegerLiteral -- comment-only; the two comments were on the wrong branches.

  • Fix null cursor passed to GetRemappedTypeName -- in VisitCharacterLiteral, the BinaryOperator branch passed the always-null implicitCastExpr (from the sibling ImplicitCastExpr branch) instead of binaryOperator.

Build is 0 warnings / 0 errors; all 3708 generator unit tests pass with byte-identical golden output. No regression tests added -- the unit-test project is purely golden-file (inputContents -> expectedOutputContents) and these triggering inputs aren't reproducible through C fixtures.

Note

This PR body was drafted by Copilot.

tannergooding and others added 2 commits July 12, 2026 20:47
Guard against empty token arrays in VisitMacroDefinitionRecord and a missing quoted string in the uuid attribute text, and fix the swapped int32-range comments in VisitIntegerLiteral.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…in binary operators

The BinaryOperator branch in VisitCharacterLiteral passed the always-null implicitCastExpr from the sibling ImplicitCastExpr branch instead of binaryOperator.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 13fd0d1 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-generator-robustness-guards branch July 13, 2026 03:59
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.

1 participant