mcp: make cbm_path_within_root parseable without the preprocessor#960
Open
DeusData wants to merge 1 commit into
Open
mcp: make cbm_path_within_root parseable without the preprocessor#960DeusData wants to merge 1 commit into
DeusData wants to merge 1 commit into
Conversation
cbm_path_within_root used an #ifdef _WIN32/#else that opened the if(...) {
brace in each branch and shared a single close brace. That is legal C, but it
splits the function body's braces across preprocessor branches, so a
source-level parser running without the preprocessor (e.g. the tree-sitter
code indexer) sees unbalanced braces, emits an error node, and never creates a
Function node for it — the definition went missing from the graph while its
callers stayed linked to an unresolved name.
Extract a small per-OS resolve_canonical_path() helper so the function has one
unconditional control flow. Behavior is unchanged (the path-containment
security tests still pass); it now indexes correctly.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
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.
Problem
cbm_path_within_root(the containment guard every MCP file-read sink passes through) was missing from the code knowledge graph — despite its callers being present. Root cause: its definition usedThat's legal C, but the
#ifdefsplits the function body's braces across preprocessor branches. A source-level parser that runs without the preprocessor (the tree-sitter-based indexer) sees twoif {opens and one}close → unbalanced → error node → noFunctionnode emitted.Change
Extract a tiny per-OS
resolve_canonical_path()helper (each#ifdefbranch is now a complete statement), leavingcbm_path_within_rootwith one unconditionalif. Purely structural — behavior is identical.Verification
mcp_path_within_root_rejects_escapeandpath_within_root_allowedstill pass; full C build + lint clean.cbm_path_within_rootnow appears as aFunctionnode within_degree=6(all callers resolve to it), and the newresolve_canonical_pathhelper is linked. Before this change it was absent from the graph entirely.The general extractor limitation (functions whose braces are split by
#ifdef) is tracked separately as an issue; this PR fixes the one security-relevant function and removes a genuine code smell.