Linking Callees Instead of Retrieving Them: Fuzzy-Matched Context for Inter-Procedural Vulnerability Detection

A language model asked whether a single C function is vulnerable often cannot answer. The bug may depend on what a helper function does two calls away, such as freeing a buffer or skipping a bounds check. The obvious fix is to paste those helpers into the prompt, and it often backfires: the model gets distracted by pages of irrelevant code. We propose treating each helper the way entity-linking systems treat an ambiguous name in a short tweet. Instead of pasting the helper, we match it against a catalogue of functions whose behavior and security history are already known. The matching is fuzzy, meaning it tolerates renamed variables, reformatting, and small edits. When it finds a confident match, we inject a one- or two-line description of the matched function ("near-copy of libpng's png_read_row pre-patch version; writes past buffer end when width is unchecked"). When no confident match exists, we inject nothing beyond a signature.

The bet is that this gives the model what is missing from an isolated function while avoiding the attention dilution that raw context causes. It also carries information that no amount of re-reading the helper provides: whether a near-copy of it was once patched for a vulnerability. In two sentences: the problem is that a function checked on its own lacks context, while its surrounding code overwhelms the model. The fix is to fuzzy-match each surrounding function against a catalogue of already-characterized functions and inject only short, confidence-gated descriptions of the matches.

Core Claim

Three findings in the literature motivate the claim. Real vulnerabilities are frequently inter-procedural. On the Effectiveness of Function-Level Vulnerability Detectors for Inter-Procedural Vulnerabilities finds that 24.3% of cases span an average of 2.8 function layers, and learned detectors lose 18.7% F1 when asked to find the triggering function. Adding context helps, but only in controlled doses. VulEval reports up to 26% improvement from repository dependencies, yet it names dependency retrieval as the bottleneck because retrievers pull in distracting non-vulnerable functions. Repoformer finds that in up to 80% of code-completion cases retrieved snippets do not help or actively confuse the model.

The closest prior work is PacVD, Context-Enhanced Vulnerability Detection Based on Large Language Models. PacVD already shows that abstracted context beats raw code. It traces the call graph up to three layers and summarizes only primitive resource APIs such as malloc, free, open, and socket. Its performance declined when it added variable-level data flow, which the authors attribute to imprecise alias analysis. PacVD's abstraction vocabulary is therefore a fixed, hand-chosen list of standard APIs. It cannot describe project-specific helpers or logic unrelated to resource management. It also becomes noisy exactly when it tries to be more precise through static analysis.

We claim that the abstraction vocabulary can be learned from other code instead of hand-picked. Fuzzy code matching can attach a vetted description, and where available a patch history, to any callee or caller that resembles a previously characterized function. Gating this injection on match confidence gives a selection rule that does not depend on alias analysis. The testable consequence has two parts. On inter-procedural vulnerabilities, linked context should beat both raw dependency injection and PacVD at equal or smaller prompt size. Its accuracy should also stay roughly flat as call depth grows, while raw-context accuracy declines.

Research Program

The system has three parts.

The first part is a catalogue of characterized functions. We build it from the PatchDB + NVD collection used by FIRE, which contains 22,041 vulnerable/patched function pairs, and from widely vendored C libraries. Each entry stores four things: a normalized body, a short behavioral summary generated once offline and spot-checked by hand, a machine-extracted list of resource effects, and, for PatchDB entries, both the pre-patch and post-patch versions. Storing both versions lets a match report which version the callee resembles more. This follows FIRE's practice of comparing candidates against vulnerable and patched references.

The second part is the linker. For a target function we collect callers and callees up to three layers, matching PacVD's depth. We then match each one against the catalogue using FIRE's cheap cascade, token-Jaccard followed by AST-subtree similarity, and confirm survivors with an embedding comparison. The idea of looking at the whole neighborhood jointly, rather than matching each helper independently, is borrowed from collective entity disambiguation in AIDA. Its reported failure mode, where a dominant topic pulls unrelated mentions toward wrong candidates, is why we match per-callee first. We use joint coherence only as a tie-breaker. Callees below a confidence threshold, tuned on a development split, are marked unlinked, the analogue of entity linking's NIL case. They receive only their signature.

The third part is the prompt. The target function appears verbatim. Linked neighbors appear as one or two lines each, in call order, placed near the question. This placement follows RepoBench, which found that putting relevant context close to the generation point reduces dilution.

There is one confound we must control. If the target function itself fuzzy-matches a known-vulnerable catalogue entry, the task becomes recurring-vulnerability detection, which FIRE already solves. We therefore exclude catalogue entries that match the target above threshold. Following the leakage warnings in The adverse effects of code duplication in machine learning models of code, we also deduplicate the catalogue against all test projects and report target-level FIRE matching as a separate reference.

Baselines

The naive reference is the function alone, with the same reader model and prompt template. This measures the cost of missing context.

The second baseline is raw dependency injection in the style of VulEval. Callers and callees are retrieved lexically, which VulEval, RepoBench, and CrossCodeEval all found competitive with or better than neural retrieval. They are concatenated up to a fixed token budget. We run it at the same token budget as our method and also at unrestricted budget, so it cannot be dismissed as starved. Beating it requires higher F1 at equal or lower budget.

The strongest existing method is PacVD. On NVD-New it reports a peak F1 of 69.09% using DeepSeek-R1 with chain-of-thought at API Level 3 (PacVD). We will reproduce PacVD Level 3 on NVD-New with the same reader and prompting. We then combine PacVD's primitive-API summary with our linked descriptions, and also run our descriptions alone. Beating PacVD means an F1 gain over the reproduced Level-3 number that exceeds seed and prompt variance. The gain should concentrate on samples whose relevant helpers are not primitive APIs.

The most dangerous competitor is on-the-fly LLM summarization of each callee. The same reader model writes one or two lines per neighbor from its raw body, and these summaries replace the linked descriptions at matched token count. It is run with the same neighbors and the same compute budget.

Two ablations isolate the key ingredients. The first removes patch history from catalogue entries, keeping only behavioral summaries; this measures what the known-vulnerability transfer adds. The second removes the confidence gate and injects the nearest catalogue entry for every neighbor; this measures whether abstention matters.

The upper reference is an oracle that injects the gold triggering function from InterPVD. No reported result exists on Lacuna for an LLM reader with oracle trigger context on InterPVD. The file reports VulTrigger's 69.8% trigger-identification accuracy, but that is a different, patch-dependent task.

Why not just…?

Why not just have the LLM summarize each callee itself? This is the real threat. If on-the-fly summaries match linked descriptions, then fuzzy matching contributes nothing but a cache. We expect two advantages. Catalogue entries are written with the helper's own callees in view and are checked, whereas per-prompt summaries can hallucinate. Pre-patch/post-patch resemblance is information no summary of the local body contains. The no-history ablation settles this. If linked context without history ties the self-summary baseline, and linked context with history beats it, the contribution is history transfer and we will say so. If both tie, the idea reduces to summarization and the claim fails.

Why not just use a long-context model and include everything? CrossCodeEval shows a large gap below perfect accuracy even when the exact gold context is supplied. Repoformer shows most retrieved code does not help, and Less is More finds that shorter specifications beat verbose ones in program synthesis. Our depth-sweep experiment tests this directly for vulnerability detection by plotting F1 against call depth and prompt length for each representation.

Why not just extend PacVD's API list or its static analysis? PacVD's own Level-4 result shows that finer static data flow hurt because of alias imprecision. Hand-extending the API list does not reach project-specific wrappers or non-resource logic. We will stratify NVD-New and InterPVD samples by whether the relevant helper is a primitive API. Our gains should appear mainly where it is not; if they do not, PacVD's existing list already suffices.

Why not just run FIRE on the target? FIRE finds recurring copies of the target function itself. Its authors attribute its false positives to vulnerabilities that span function boundaries. We report FIRE's target-level matches separately, and we exclude those cases from our method's credit.

Proposed Experiments

The primary benchmark is InterPVD, restricted to its caller-type and callee-type cases. We score function-level detection and a paired test: does the model rank the vulnerable version of a function above its patched version, given the same neighbors? The paired test cancels biases toward calling everything vulnerable. We also run NVD-New for direct comparison with PacVD, and VulEval's repository-level detection under its time split for scale. Metrics are F1, precision, recall, paired accuracy, and prompt tokens. We use at least one reasoning model matching PacVD and one open code model, with three prompt seeds.

Three checks decide the outcome.

First, the depth sweep from one to three call layers. Linked context should hold F1 roughly constant while raw injection falls. Parallel curves would mean the benefit is not noise resistance.

Second, stratification by link rate. Gains should grow with the fraction of neighbors linked above threshold. A gain of similar size in low-link samples would indicate the improvement comes from formatting, not matching.

Third, the history and gating ablations. These identify which ingredient carries the effect.

A clear negative outcome would also be informative. It would mean fuzzy code matching, although effective for finding clones, does not transfer the right semantics to resolve missing context for an LLM reader.