fix(parsers/c): guard macro-alias resolution against cyclic #defines#130
Open
gadievron wants to merge 1 commit into
Open
fix(parsers/c): guard macro-alias resolution against cyclic #defines#130gadievron wants to merge 1 commit into
gadievron wants to merge 1 commit into
Conversation
_resolve_call recursed on a macro alias target with no visited-set, so a cyclic
function-like #define pair ({"A":"B","B":"A"}) looped A->B->A->... until
RecursionError aborted the entire repository's C call-graph build. Thread an
_alias_chain set through the recursion so a cyclic alias resolves to None.
Stacked on pr/zig-php-generic-anon, whose C-parser rework carries the same
unguarded macro recursion; this layers the cycle guard on top of that signature.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Finding F4 (HIGH). |
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.
fix(parsers/c): guard macro-alias resolution against cyclic #defines
Base:
pr/zig-php-generic-anon· Depends-on: #127 · Type: bug fix · Finding: F4 (HIGH)What
parsers/c/call_graph_builder.py—_resolve_callthreads an_alias_chainvisited-set through its macro-alias recursion, so a cyclic alias resolves to
Noneinstead of recursing forever.Why
macro_aliasesis built from function-like#defines. A cyclic pair —#define A(x) B(x)/#define B(x) A(x)→{"A":"B","B":"A"}— made_resolve_call("A")recurseA→B→A→…with no guard →RecursionError.build_call_graphiterates every function with no try/except, so one poisoneddefine pair aborts the entire repository's C call-graph build (seen on vendored
LLVM in ziglang/zig). A self-alias was already safe via the
resolved_name != call_nameshort-circuit; only 2+ node cycles triggered it.Tests
tests/test_c_macro_alias_cycle.py(new): 2-node cycle, 3-node cycle, self-alias.RecursionError.Upstream coordination
The cyclic-macro recursion is live on master, on the C staging stack (#114/#121),
and on #127 — all unguarded. This guard is non-overlapping with those refactors;
sequence after #127 (or the C stack), re-anchoring onto the post-rework
_resolve_call.Author notes
if resolved_name not in _alias_chain:guard around therecursive
_resolve_call(..., _alias_chain=_alias_chain).#definemacro pairs that crashed the whole-repoparse.
cycle with no arbitrary limit, mirroring the file's other visited guards.