@@ -402,13 +402,55 @@ module RustDataFlow implements InputSig<Location> {
402402
403403 final class ReturnKind = ReturnKindAlias ;
404404
405+ private import codeql.util.Option
406+
407+ private class CrateOrigin extends string {
408+ CrateOrigin ( ) {
409+ this = [ any ( Item i ) .getCrateOrigin ( ) , any ( Resolvable r ) .getResolvedCrateOrigin ( ) ]
410+ }
411+ }
412+
413+ private class CrateOriginOption = Option< CrateOrigin > :: Option ;
414+
415+ pragma [ nomagic]
416+ private predicate hasExtendedCanonicalPath (
417+ DataFlowCallable c , CrateOriginOption crate , string path
418+ ) {
419+ exists ( Item i |
420+ i = c .asCfgScope ( ) and
421+ path = i .getExtendedCanonicalPath ( )
422+ |
423+ crate .asSome ( ) = i .getCrateOrigin ( )
424+ or
425+ crate .isNone ( ) and
426+ not i .hasCrateOrigin ( )
427+ )
428+ }
429+
430+ pragma [ nomagic]
431+ private predicate resolvesExtendedCanonicalPath (
432+ DataFlowCall c , CrateOriginOption crate , string path
433+ ) {
434+ exists ( Resolvable r |
435+ path = r .getResolvedPath ( ) and
436+ (
437+ r = c .asMethodCallExprCfgNode ( ) .getExpr ( )
438+ or
439+ r = c .asCallExprCfgNode ( ) .getExpr ( ) .( PathExprCfgNode ) .getPath ( )
440+ )
441+ |
442+ crate .asSome ( ) = r .getResolvedCrateOrigin ( )
443+ or
444+ crate .isNone ( ) and
445+ not r .hasResolvedCrateOrigin ( )
446+ )
447+ }
448+
405449 /** Gets a viable implementation of the target of the given `Call`. */
406- DataFlowCallable viableCallable ( DataFlowCall c ) {
407- exists ( Function f , string name | result .asCfgScope ( ) = f and name = f .getName ( ) .toString ( ) |
408- if f .getParamList ( ) .hasSelfParam ( )
409- then name = c .asMethodCallExprCfgNode ( ) .getNameRef ( ) .getText ( )
410- else
411- name = c .asCallExprCfgNode ( ) .getExpr ( ) .getExpr ( ) .( PathExpr ) .getPath ( ) .getPart ( ) .toString ( )
450+ DataFlowCallable viableCallable ( DataFlowCall call ) {
451+ exists ( string path , CrateOriginOption crate |
452+ hasExtendedCanonicalPath ( result , crate , path ) and
453+ resolvesExtendedCanonicalPath ( call , crate , path )
412454 )
413455 }
414456
0 commit comments