Skip to content

Commit 4615210

Browse files
authored
feat-fix: eval hook
1 parent 68affe8 commit 4615210

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/taint-analysis/builder/taint-analysis.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export interface FnCallHookInfo {
2525
role: TaintRole | undefined;
2626
/** The AST node representing the function call */
2727
node: RNamedFunctionCall<ParentInformation>;
28+
/** Whether the function call had an explicit mapping */
29+
wasMapped: boolean;
2830
/** The abstract domain value at this point (the outgoing/resolved taint) */
2931
value: AnyAbstractDomain;
3032
/** Resolves the incoming taint of any argument node at this call, regardless of mapping rules */
@@ -144,7 +146,7 @@ export class TaintAnalysis<Defs extends readonly string[] = []> {
144146

145147
private wrapFnCallHook(fn: FnCallHook | undefined, name: string, dfg: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext): TaintVisitorHook {
146148
return fn
147-
? ({ node, value, projectArg, call, role }) => fn({ name, node, value, projectArg, call, dfg, ctx, role })
149+
? ({ node, value, wasMapped, projectArg, call, role }) => fn({ name, node, value, wasMapped, projectArg, call, dfg, ctx, role })
148150
: () => {};
149151
}
150152
}

src/taint-analysis/eval/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class TaintAnalysisInstrumentation {
7474
return this._trace;
7575
}
7676

77-
fnCallHook = ({ name, node, value, projectArg, call, dfg, ctx, role }: FnCallHookInfo) => {
77+
fnCallHook = ({ name, node, value, wasMapped, projectArg, call, dfg, ctx, role }: FnCallHookInfo) => {
7878
const fnCallInfo = this.addFile(name, node);
7979
const localTargets = satisfiesCallTargets(call, dfg, CallTargets.OnlyLocal);
8080
const cds = call.cds?.map(cd => resolveControlDependency(cd, dfg));
@@ -86,7 +86,7 @@ export class TaintAnalysisInstrumentation {
8686
...(localTargets === 'no' ? {} : { localTargets }),
8787
...(cds?.length ? { cds, inEveryBranch: happensInEveryBranch(call.cds) } : {}),
8888
};
89-
if(value) {
89+
if(wasMapped) {
9090
fnCallInfo.mappedCalls.push({ ...callInfo, taint: value.toJSON(), role });
9191
} else {
9292
fnCallInfo.unmappedCalls.push(callInfo);

src/taint-analysis/taint-visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class TaintInferenceVisitor<Domain extends AnyAbstractDomain> extends Abs
6363
const { value, role } = resolveFnCallToTaint(node, mappings, this.domain, this.projectArg, this.config.dfg, this.config.ctx);
6464
this.currentState.set(node.info.id, value);
6565

66-
this.config.fnCallHook({ node, value, projectArg: this.projectArg, call, role: role });
66+
this.config.fnCallHook({ node, value, wasMapped: mappings.length > 0, projectArg: this.projectArg, call, role: role });
6767
}
6868

6969
protected isUnsupportedFunctionCall(_nodeId: NodeId): boolean {

0 commit comments

Comments
 (0)