From dcfa721037e71d150195265167a69db6e744c3f9 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Wed, 26 Nov 2025 10:17:49 +0000 Subject: [PATCH] (Refactor) Make `lookThroughImplicitFieldRead` public --- go/ql/lib/semmle/go/controlflow/IR.qll | 5 +++++ .../go/dataflow/internal/FlowSummaryImpl.qll | 16 ++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go/ql/lib/semmle/go/controlflow/IR.qll b/go/ql/lib/semmle/go/controlflow/IR.qll index 2c8b673184e..144f0df6e7d 100644 --- a/go/ql/lib/semmle/go/controlflow/IR.qll +++ b/go/ql/lib/semmle/go/controlflow/IR.qll @@ -1588,4 +1588,9 @@ module IR { * in a field/method access, element access, or slice expression. */ EvalImplicitDerefInstruction implicitDerefInstruction(Expr e) { result = MkImplicitDeref(e) } + + /** Gets the base of `insn`, if `insn` is an implicit field read. */ + Instruction lookThroughImplicitFieldRead(Instruction insn) { + result = insn.(ImplicitFieldReadInstruction).getBaseInstruction() + } } diff --git a/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll b/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll index f12c9e6eeb1..f4ad3862da0 100644 --- a/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll +++ b/go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll @@ -384,17 +384,13 @@ module SourceSinkInterpretationInput implements } private DataFlow::Node skipImplicitFieldReads(DataFlow::Node n) { - not exists(lookThroughImplicitFieldRead(n)) and result = n + not exists(IR::lookThroughImplicitFieldRead(n.asInstruction())) and result = n or - result = skipImplicitFieldReads(lookThroughImplicitFieldRead(n)) - } - - private DataFlow::Node lookThroughImplicitFieldRead(DataFlow::Node n) { - result.asInstruction() = - n.(DataFlow::InstructionNode) - .asInstruction() - .(IR::ImplicitFieldReadInstruction) - .getBaseInstruction() + exists(DataFlow::Node mid | + mid.asInstruction() = IR::lookThroughImplicitFieldRead(n.asInstruction()) + | + result = skipImplicitFieldReads(mid) + ) } /** Provides additional sink specification logic. */